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. ARM架构解析

    ARM架构解析 (2014-11-23 21:56:53) 转载▼ 标签: francis_hao arm架构 arm核 soc 分类: MCU 先来谈一下ARM的发展史:1978年12月5日,物理学 ...

  2. POJ 2686 Traveling by Stagecoach

    状压DP dp[s][p]用了哪几张票,到哪个节点的最小费用. 注意:G++ %.3lf输出会WA,但C++能过:改成%.3f,C++,G++都能AC #include<cstdio> # ...

  3. Java笔记(二)

    10.   public protected default private 同一个类中 √ √ √ √ 同一个包中 √ √ √   子类 √ √     不同包中 √       11. 线程: s ...

  4. ASP.net 自定义控件GridView

    using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls ...

  5. (简单) POJ 3126 Prime Path,BFS。

    Description The ministers of the cabinet were quite upset by the message from the Chief of Security ...

  6. cygwin的安装,vi的使用,gcc,g++的使用(转)

    源:cygwin的安装,vi的使用,gcc,g++的使用 Gcc的Makefile简单使用

  7. iReport折线图

    1.拖动组件面板chart到Summary   2.右击-->chart data  单出   3.   4.X轴和Y轴必须是数字 series:系列 连续,串联 category:类型.部门. ...

  8. Android与JNI(二) ---- Java调用C++ 动态调用

    目录: 1. 简介 2. JNI 组件的入口函数 3. 使用 registerNativeMethods 方法 4. 测试 5. JNI 帮助方法 6. 参考资料 1. 简介 Android与JNI( ...

  9. 使用getParameterMap()方法实现对请求参数的封装的工具类

    我们知道,HttpServletRequest这个类的getParameter(name),getParameterValues(name)可以分别实现对页面传来的单个参数和对多个同名参数的接受.特别 ...

  10. python3中bytes与string的互相转换

    首先来设置一个原始的字符串, Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32 Ty ...