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;
}

【codeforces 750C】New Year and Rating(做法2)的更多相关文章

  1. 【codeforces 750C】New Year and Rating

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. CodeForces - 792C Divide by Three (DP做法)

    C. Divide by Three time limit per test: 1 second memory limit per test: 256 megabytes input: standar ...

  3. Codeforces Global Round 12 D. Rating Compression (思维,双指针)

    题意:给你一长度为\(n\)的数组,有一长度为\(k\ (1\le k \le n)\)的区间不断从左往右扫过这个数组,总共扫\(n\)次,每次扫的区间长度\(k=i\),在扫的过程中,每次取当前区间 ...

  4. Codeforces 85 D. Sum of Medians

    题目链接:http://codeforces.com/contest/85/problem/D 做法果然男默女泪啊..... 大概就是直接开了一个$vector$每次插入删除都用自带的$insert$ ...

  5. Running to the End(Codeforces & AtCoder 百套计划)

    ...Reserved for the future... 仿照xxy dalao的CF&CC百套计划,做了一个Codeforces & AtCoder 百套计划,按这个速度刷下去,每 ...

  6. Codeforces 7E - Defining Macros 题解

    目录 Codeforces 7E - Defining Macros 题解 前言 做法 程序 结尾 Codeforces 7E - Defining Macros 题解 前言 开始使用博客园了,很想写 ...

  7. Hungary Algorithm国外板子

    Codeforces 1107一题除了dp做法还有二分带权匹配O(n^3)做法,国外网友的板子时间非常优秀,但矩阵设定的事情并不是很懂-- //Codeforces 1107F const int m ...

  8. 咕咕咕清单(SCOI2020前)

    本篇博客已停更 本篇博客已停更 本篇博客已停更 吐槽区: 2020.04.15: 从今天起我做过的题目都记录一下,想不想写题解就另说了 2020.04.17: 写了两天之后真实的发现这是博主的摸鱼日记 ...

  9. Codefroces 750C:New Year and Rating(思维)

    http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...

随机推荐

  1. HDU 1848(sg博弈) Fibonacci again and again

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  2. Android 利用代码在屏幕中间位置显示ProgressDialog和ProgressBar

    package cc.testprogressdialog; import android.os.Bundle; import android.view.Gravity; import android ...

  3. Thinkphp5创建控制器

    今天我们就来创建一个控制器: <?php namespace app\index\controller; use think\Controller; class Test extends Con ...

  4. UVA 294 294 - Divisors (数论)

    UVA 294 - Divisors 题目链接 题意:求一个区间内,因子最多的数字. 思路:因为区间保证最多1W个数字,因子能够遍历区间.然后利用事先筛出的素数求出质因子,之后因子个数为全部(质因子的 ...

  5. Oracle数据库(二)

    指令来练习 1.password,修改密码输入旧命令,在输入新的命令 2.查询当前用户 show user: 2.查询用户下的所有对象,使用tab表,tab是每一个用户都有的 select *from ...

  6. python3中numpy函数tile的用法

    tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组.比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题 ...

  7. UVA 10603 - Fill BFS~

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&c ...

  8. 使用前端后台管理模板库admin-lte(转)

    使用前端后台管理模板库admin-lte 使用前端后台管理模板库admin-lte 安装 搭建环境 安装 安装admin-lte,可以通过以下几种办法安装,下图是GitHub中admin-lte的主页 ...

  9. Spring资源抽象Resource

    JDK操纵底层资源基本就是 java.net.URL .java.io.File .java.util.Properties这些.取资源基本是根据绝对路径或当前类的相对路径来取.从类路径或Web容器上 ...

  10. Compmgmtlauncher.exe问题解决方法

    修改注册表:HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Manage\command   原来的默认键值为 ...