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. Javascript隔离方法

    1.常用的隔离方法: (function() { })(); 2.query的隔离方法: 需要引入jquery: <script type="text/javascript" ...

  2. 在mac本上删除mysql

    The steps: First you need to edit the file in: /etc/hostconfig and remove the line Since this is a s ...

  3. 更多文章请关注公众号:FullStackPlan 或前往个人主页:www.linbingdong.com

    个人主页:www.linbingdong.com 扫一扫关注公众号: FullStackPlan 获取更多干货哦~

  4. oracle 11g odbc连接串及配置

    首先先安装HA-Instant Client-v11.2.0.3.0-x86.rar 下载地址: ftp://hhdown:2-2@58.23.131.52/download/HA-Instant%2 ...

  5. iOS开发 调用系统相机和相册 分类: ios技术 2015-03-30 15:52 65人阅读 评论(0) 收藏

     调用系统相机和相册 (iPad,iPhone) 打开相机:(iPad,iPhone) //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为 ...

  6. FTP-使用记录

    1.磁盘配额不够用 Could not write to transfer socket: ECONNABORTED - 连接中止 452-Maximum disk quota limited to ...

  7. bitmap资源回收

    这个问题哎,困扰本宫一天! bitmap不完全解决method: http://blog.csdn.net/hahahacff/article/details/8540942 http://blog. ...

  8. ModelDriven动作(转)

    所谓ModelDriven ,意思是直接把实体类当成页面数据的收集对象.比如,有实体类User 如下: package cn.com.leadfar.struts2.actions; public c ...

  9. zip-auto.sh

    #!/bin/sh #auto zip package #Define Path #####test######### mkdir -p /root/shell/test1 /root/shell/t ...

  10. c++ split()实现

    在c++中,没有java与python中定义的split()功能的函数,于是自己实现之. 情况1,适用范围,分隔符为字符.思路,记录分隔符的位置,判断需要截取的字符串的下标范围. vector< ...