CF 750C New Year and Rating(思维题)
题目链接: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 rating1900or higher. Those with rating1899or 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 inncontests in the year 2016. He remembers that in thei-th contest he competed in the divisiondi(i.e. he belonged to this divisionjust beforethe start of this contest) and his rating changed bycijust after the contest. Note that negativecidenotes the loss of rating.
What is the maximum possible rating Limak can have right now, after allncontests? 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 integern(1 ≤ n ≤ 200 000).
Thei-th of nextnlines contains two integerscianddi( - 100 ≤ ci ≤ 100,1 ≤ di ≤ 2), describing Limak's rating change after thei-th contest and his division during thei-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 thencontests.
Examples
input
3<br />-7 1<br />5 2<br />8 2
output
1907
input
2<br />57 1<br />22 2
output
Impossible
input
1<br />-5 1
output
Infinity
input
4<br />27 2<br />13 1<br />-50 1<br />8 2
output
1897
Note
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating:
- Limak has rating1901and belongs to the division1in the first contest. His rating decreases by7.
- With rating1894Limak is in the division2. His rating increases by5.
- Limak has rating1899and is still in the division2. In the last contest of the year he gets + 8and ends the year with rating1907.
In the second sample, it's impossible that Limak is in the division1, his rating increases by57and after that Limak is in the division2in 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 }