Good Bye 2016 C. New Year and Rating思维
2017-01-08 15:33
316 查看
C. New Year and Rating
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
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 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
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 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.
题意:在codeforce中给出n次比赛的情况,ci表示分数变化di表示你参加的是V1还是V2,问你最高分是多少,无解输出impossible,无穷大输出infinity。
题解:我们定一个上界和下界,每次根据参加的场和得分情况修改上下界,最后判断。注意,我们能得到的最高分是初始分为1899 连续n场涨100分,既最高分为20001899(n=max)。当大于这个分数的都是无穷大。
代码:
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
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 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
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 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.
题意:在codeforce中给出n次比赛的情况,ci表示分数变化di表示你参加的是V1还是V2,问你最高分是多少,无解输出impossible,无穷大输出infinity。
题解:我们定一个上界和下界,每次根据参加的场和得分情况修改上下界,最后判断。注意,我们能得到的最高分是初始分为1899 连续n场涨100分,既最高分为20001899(n=max)。当大于这个分数的都是无穷大。
代码:
#include <bits/stdc++.h> #define ll long long #define bababaa printf("!!!!!!!\n") using namespace std; const ll INF=3e8; ll l,r; int x,y; int main() { int n; cin>>n; l=-INF; r=INF; while(n--) { cin>>x>>y; if(y==1&&l<1900) l=1900; if(y==2&&r>1899) r=1899; l+=x; r+=x; } if(l>r) { puts("Impossible"); } else if(max(l,r)>20001899) puts("Infinity"); else cout<<max(l,r)<<endl; }
相关文章推荐
- Good Bye 2016 C. New Year and Rating(二分)
- Codeforces Good Bye 2016 D. New Year and Fireworks(bfs/dfs)
- Good Bye 2016 C. New Year and Rating(二分)
- Good Bye 了 2016
- CodeFroces--Good Bye 2016-B--New Year and North Pole(水题-模拟)
- codeforces Good Bye 2016-B New Year and North Pole
- codeforces Good Bye 2016
- codeforces Good Bye 2016-C New Year and Rating(二分)
- Codeforces Good Bye 2016 D 模拟搜索?
- Good Bye 2016 C. New Year and Rating 不等式+贪心、数学
- Codeforces Good Bye 2016 题解
- Good Bye 2016 D. New Year and Fireworks dp+枚举、状态总数
- Codeforces Good Bye 2016 C. New Year and Rating(模拟)
- Codeforces Good Bye 2016部分题解
- Good Bye 2016(A+B)
- Codeforces Good Bye 2016 C.New Year and Rating//qduoj 三亿河老师的上分梦想
- codeforces Good Bye 2016
- CodeForces Good Bye 2016 :C New Year and Rating、D New Year and Fireworks、E New Year and Old Subsequ
- codeforces Good Bye 2016-D New Year and Fireworks(dfs)
- Good Bye 2016 题解(待续)