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.

思路:设立一个上下限l=-inf, r=inf.然后根据从c[i] d[i] 和 c[i]的累计值s来不断更新l r;最后判断若r小于f则 “Impossible” ,若上界未改变则为“Infinity”。

eg:若d[i]=2,则r=min(r,1899-s) .若d[i]=1,则l=max(l,1900-s);

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#define pi acos(-1.0)
#define mj
#define inf 2e8+500
typedef long long ll;
using namespace std;
const int N=2e5+;
int c[N],d[N];
int main()
{
int n;
scanf("%d",&n);
int l=-inf,r=inf;
int s=;
for(int i=;i<n;i++){
scanf("%d%d",&c[i],&d[i]);
if(d[i]==){
l=max(l,-s);
}
else{
r=min(r,-s);
}
s+=c[i];
}
if(r<l){
printf("Impossible\n");
}
else if(r==inf){
printf("Infinity\n");
}
else {
printf("%d\n",r+s);
}
return ;
}

codeforces div2.C的更多相关文章

  1. codeforces DIV2 D 最短路

    http://codeforces.com/contest/716/problem/D 题目大意:给你一些边,有权值,权值为0的表示目前该边不存在,但是可以把0修改成另外一个权值.现在,我们重新建路, ...

  2. codeforces div2 677 D

    http://codeforces.com/problemset/problem/677/D 题目大意: 给你一个n*m的图,上面有p种钥匙(p<=n*m),每种钥匙至少有一个,期初所有为1的钥 ...

  3. codeforces div2 603 D. Secret Passwords(并查集)

    题目链接:https://codeforces.com/contest/1263/problem/D 题意:有n个小写字符串代表n个密码,加入存在两个密码有共同的字母,那么说这两个密码可以认为是同一个 ...

  4. codeforces div2 603 E. Editor(线段树)

    题目链接:https://codeforces.com/contest/1263/problem/E 题意:一个编译器,每次输入一些字符,R表示光标右移,L表示光标左移,然后有一些左括号(  和 右括 ...

  5. codeforces div2 603 C. Everyone is a Winner!(二分)

    题目链接:https://codeforces.com/contest/1263/problem/C 题意:给你一个数字n,求n/k有多少个不同的数 思路:首先K大于n时,n/k是0.然后k取值在1到 ...

  6. codeforces div2 220 解题

    这套题我只写了a, b, c..  对不起,是我太菜了. A:思路:就是直接简化为一个矩阵按照特定的步骤从一个顶角走到与之对应的对角线上的顶角.如图所示. 解释一下特定的步骤,就像马走日,象走田一样. ...

  7. codeforces div2 C题思路训练【C题好难,我好菜】

    1017C The Phone Number: 构造数列使得LIS和LDS的和最小,定理已知LIS=L,LDS=n/L的向上取整,根据样例可以得到设置L=根号n,构造方法如样例 截断法构造,不用考虑边 ...

  8. Codeforces div2 #499 B. Planning The Expedition 大水题

    已经是水到一定程度了QAQ- Code: #include<cstdio> #include<algorithm> #include<cstring> using ...

  9. NOI前训练日记

    向别人学习一波,记点流水帐.17.5.29开坑. 5.29 早晨看了道据说是树状数组优化DP的题(hdu5542),然后脑补了一个复杂度500^3的meet in the middle.然后死T... ...

随机推荐

  1. CollapsingToolbarLayout学习笔记

    CollapsingToolbarLayout包裹 Toolbar 的时候提供一个可折叠的 Toolbar,一般作为AppbarLayout的子视图使用. <?xml version=" ...

  2. 基于Keepalvied的Mysql主主漂移(切换)

    Keepalived实现原理:Keepalived详细介绍简介 实验环境 Master1.Amoeba--IP:192.168.1.5 Master2---IP:192.168.1.10 同时安装ke ...

  3. DNS远程和DNS日志

    三.rndc远程控制服务器 1.在被管理的服务器上生成密钥 # cd /var/named/chroot/etc # rndc-confgen -a -b 128 -k mrndc-key -c mr ...

  4. php中使用mysql_fetch_object向页面输出结果,总结!

    public function selectResultByThird() { if ((!empty ($_REQUEST["bigname"])) && (!e ...

  5. iOS 获取本地文件的各种坑

    1.无论:TXT,EPUB,PDF等各种格式的文件,保存到本地的时候,最好都保存成字母或者数字,不要保存成汉字,否则,在取文件的时候,由于编码的问题,各种瓦特 2.如果文件名真的保存成了汉字,那么进行 ...

  6. JQuery EasyUI DataGrid 获取属性值

    在Jquery EasyUI中返回操作的时候,根据当前页返回到数据选取页: var grid = $('#datagrid'); var options = grid.datagrid('getPag ...

  7. IOS开发中使用AFNetworking请求网络数据

    1.把AFNetworking的文件拖放到项目中(注意不同的版本方法不一样,本历程基于版本2013): 2.使用#import "AFNetworking.h"命令把AFNetwo ...

  8. 字符串处理,NSNumber转换

    more:http://www.superqq.com/blog/categories/ioskai-fa/ 1.判断字符串是否为空 if ([text lenght] == 0) {     //  ...

  9. ECSHOP中ajax的调用原理

    ECSHOP中ajax的调用原理 ecshop中ajax的调用原理. 1.首先ecshop是如何定义ajax对象的. ecshop中的ajax对象是在js/transport.js文件中定义的.里面是 ...

  10. sql语句:CASE WHEN END 的用法

    select b,c, CASE a ' ' ' end from test1