您的位置:首页 > 编程语言 > Go语言

codeforces goodbye 2016 C. New Year and Rating

2016-12-31 10:04 435 查看
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 ncontests.

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.

//题目思路挺清晰的,当时没做出来
//当 level = 2 的时候是考虑下限
//当 level = 1 的时候是考虑上限
//每次比较时是将前面比赛的所有分数和 比较
//2016 过去了,要加油啊
#include<stdio.h>
#define inf 0x3f3f3f3f

int main()
{
int n;
int flag ,rank,level;
int total = 0;
int less = -inf;
int much = inf;
scanf("%d",&n);

for(int i=0;i<n;i++)
{
scanf("%d%d",&rank,&level);

if( level == 1)
{
if( less < 1900 - total )
less = 1900 - total;
}
if( level == 2)
{
if( much > 1899 - total)
much = 1899 - total;
}

total += rank;
}

if( much == inf)
printf("Infinity\n");
else if( less > much )
printf("Impossible\n");
else printf("%d\n",much+total);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: