新的一年,希望自己能变得不那么菜了OvO
New Year and Rating
time limit per test 2 second memory limit per test 256 megabytes
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”.

传送门:CF750C

Input

The first line of the input contains a single integer n (1≤n≤200000). 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.

Sample Input

1
2
3
4
3
-7 1
5 2
8 2

Sample Output

1
1907

题解

要想明白是需要时间的= = 碰到div1时决定的是下限 碰到div2时决定的是上限 每次影响的因素是前面所有改变之和 其他都是玄学
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;  
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
int[] score=new int[n];
int[] div=new int[n];
for(int o=0;o<n;o++){
score[o]=sc.nextInt();
div[o]=sc.nextInt();
}
long max=Integer.MAX_VALUE; //上界
long min=Integer.MIN_VALUE; //下界
int sum=0;
for(int i=0;i<n;i++){
if(div[i]==1){
if(min<1900-sum)
min=1900-sum;
}
if(div[i]==2){
if(max>1899-sum){
max=1899-sum;
}
}
sum=sum+score[i];
}
if(min>max){
System.out.println("Impossible");
}
else if(max==Integer.MAX_VALUE){
System.out.println("Infinity");
}
else
System.out.println(max+sum);
}
}
}