题目链接:http://codeforces.com/problemset/problem/750/C
题目:
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one‘s performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division di (i.e. he belonged to this division just before the start of this contest) and his rating changed by ci just after the contest. Note that negative ci denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000).
The i-th of next n lines contains two integers ci and di ( - 100 ≤ ci ≤ 100, 1 ≤ di ≤ 2), describing Limak‘s rating change after the i-th contest and his division during the i-th contest contest.
Output
If Limak‘s current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak‘s current rating, i.e. rating after the n contests.
Examples
input
3-7 15 28 2
output
1907
input
257 122 2
output
Impossible
input
1-5 1
output
Infinity
input
427 213 1-50 18 2
output
1897
Note
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating:
- Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7.
- With rating 1894 Limak is in the division 2. His rating increases by 5.
- Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it‘s impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
题意:模拟CF比赛,分为div1和div2,给定n场对应级数的比赛结果,求最后能够得到的最大分数。
题解:创建两个边界,以两边不断压缩。div1的时候,若左边界小于1900,左边界上升到1900,然后再加;同理div2的时候,若右边界高于1899,右边界降低到1899,然后再加;最后判断是否符合条件。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define PI acos(-1.0) 5 #define INF 0x3f3f3f3f 6 #define FAST_IO ios::sync_with_stdio(false) 7 #define CLR(arr,val) memset(arr,val,sizeof(arr)) 8 9 typedef long long LL; 10 11 int main(){ 12 int n,a,b; 13 int l=-INF,r=INF; 14 cin>>n; 15 for(int i=1;i<=n;i++){ 16 cin>>a>>b; 17 if(b==1&&l<1900) l=1900; 18 if(b==2&&r>1899) r=1899; 19 l+=a;r+=a; 20 } 21 if(l>r) cout<<"Impossible"<<endl; 22 else if(r>30000000) cout<<"Infinity"<<endl; 23 else cout<<max(l,r)<<endl; 24 return 0; 25 }
原文地址:https://www.cnblogs.com/Leonard-/p/8321742.html