time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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.

【题目链接】:http://codeforces.com/contest/750/problem/C

【题解】



设一开始的时候分数为x

则如果第一个d = 1;

则上限为INF

如果第一个d=2

则上限为1899

如果下一场比赛为div1

则x+c1+c2+..+ci>=1900

如果下一场比赛为div2

则x+c1+c2+..+ci<=1899



x>=1900-c1-c2..ci div1

x<=1899-c1-c2..ci; div2

在做的过程中搞一个前缀和

delta+=ci;

(delta=c1+c2..ci);

维护一下x的最小值和最大值;

然后用x的最大值加上delta;

就能直接获取最后的分数了;

最小值如果大于最大值,则不合法;

最大值如果为Inf就表示全是div1;

一开始的时候可以弄一个技巧

就是delta的值后加上ci;

这样delta就保留了上一次的变化;

这样就不用错开一位往后判断了;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int INF = 1e9;
const int MAXN = 2e5+10;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int n,delta,ma,mi; int main()
{
//freopen("F:\\rush.txt","r",stdin);
ma = INF,mi = -INF,delta = 0;
rei(n);
rep1(i,1,n)
{
int x,y;
rei(x);rei(y);
if (y==1)
mi = max(mi,1900-delta);
else
ma = min(ma,1899-delta);
delta+=x;
}
if (mi>ma)
{
puts("Impossible");
return 0;
}
if (ma==INF)
{
puts("Infinity");
return 0;
}
printf("%d\n",ma+delta);
return 0;
}

最新文章

  1. Android 与Unity交互之Toast消息
  2. PourOver – 快速筛选和排序大的数据集合
  3. c语言数据结构和算法库--cstl---王博--相关网站和博客
  4. Linux静态库和共享库
  5. [SSH 2] 以网站主页面浅谈Struts2配置
  6. lintcode 中等题: Implement Trie
  7. [NOIP1998]最大数
  8. (三)CodeMirror - Event
  9. ajax用户名校验demo详解
  10. AjaxHelper学习,ajax,microsoft,mvc,asp.net
  11. 使用file_get_content系列函数和使用curl系列函数采集图片的性能对比
  12. Android 异步查询框架AsyncQueryHandler的使用
  13. Android Service详解
  14. Python3.7和数据库MySQL 8.0.12 绿色解压 安装教程(一)
  15. 1.Git起步-Git的三种状态以及三种工作区域、CVCS与DVCS的区别、Git基本工作流程
  16. python第六十一天,第六十二天 redis
  17. Star Schema and Snowflake Schema
  18. Linux系统挂载只读改成读写
  19. Spring Security和JWT实现登录授权认证
  20. pyqt、webkit和qt之间的关系

热门文章

  1. Excel数据比对-批量数据比对
  2. c#中反射的用法(即如何根据字符找到已定义的变量)
  3. 洛谷 P1097 统计数字
  4. cocos2d-x 3.x游戏开发学习笔记(1)--mac下配置cocos2d-x 3.x开发环境
  5. 关于C++中用两个迭代器方式初始化string的知识
  6. spyder结束死循环的方法
  7. BAT面试常的问题和最佳答案
  8. 洛谷—— P1018 乘积最大
  9. [RxJS] RefCount: automatically starting and stopping an execution
  10. 【物理/数学】—— 概念的理解 moment、momentum