codeforces div2.C
2 seconds
256 megabytes
standard input
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".
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.
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.
3
-7 1
5 2
8 2
1907
2
57 1
22 2
Impossible
1
-5 1
Infinity
4
27 2
13 1
-50 1
8 2
1897
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的更多相关文章
- codeforces DIV2 D 最短路
http://codeforces.com/contest/716/problem/D 题目大意:给你一些边,有权值,权值为0的表示目前该边不存在,但是可以把0修改成另外一个权值.现在,我们重新建路, ...
- codeforces div2 677 D
http://codeforces.com/problemset/problem/677/D 题目大意: 给你一个n*m的图,上面有p种钥匙(p<=n*m),每种钥匙至少有一个,期初所有为1的钥 ...
- codeforces div2 603 D. Secret Passwords(并查集)
题目链接:https://codeforces.com/contest/1263/problem/D 题意:有n个小写字符串代表n个密码,加入存在两个密码有共同的字母,那么说这两个密码可以认为是同一个 ...
- codeforces div2 603 E. Editor(线段树)
题目链接:https://codeforces.com/contest/1263/problem/E 题意:一个编译器,每次输入一些字符,R表示光标右移,L表示光标左移,然后有一些左括号( 和 右括 ...
- 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到 ...
- codeforces div2 220 解题
这套题我只写了a, b, c.. 对不起,是我太菜了. A:思路:就是直接简化为一个矩阵按照特定的步骤从一个顶角走到与之对应的对角线上的顶角.如图所示. 解释一下特定的步骤,就像马走日,象走田一样. ...
- codeforces div2 C题思路训练【C题好难,我好菜】
1017C The Phone Number: 构造数列使得LIS和LDS的和最小,定理已知LIS=L,LDS=n/L的向上取整,根据样例可以得到设置L=根号n,构造方法如样例 截断法构造,不用考虑边 ...
- Codeforces div2 #499 B. Planning The Expedition 大水题
已经是水到一定程度了QAQ- Code: #include<cstdio> #include<algorithm> #include<cstring> using ...
- NOI前训练日记
向别人学习一波,记点流水帐.17.5.29开坑. 5.29 早晨看了道据说是树状数组优化DP的题(hdu5542),然后脑补了一个复杂度500^3的meet in the middle.然后死T... ...
随机推荐
- 路过Haxe
刚才在看Nape的时候,看到Haxe的代码,意外的感觉到亲切. 因为之前写过as2代码,最近学习了python,所以对haxe看起来很亲切,于是路过一下写了个HelloWorld. 另外,估计很长时间 ...
- openstack controller ha测试环境搭建记录(三)——配置haproxy
haproxy.cfg请备份再编辑:# vi /etc/haproxy/haproxy.cfg global chroot /var/lib/haproxy daemon group ...
- DNS正、反解析查询指令host、dig、nslookup
一.host指令格式:host [-a] FQDN [server] host -l domain [server]选项:-a :代表列出该主机所有的相关信息,包括 IP.TTL 与除错讯息等等-l ...
- PHPCMS v9 列表页实现文件下砸
{template "content","header"} <div class="list"> <div class=& ...
- 五、Hive
一.Hive 1.1 Hive简介 1.2 Hive说明 1.3Hive的体系架构 来自为知笔记(Wiz)
- Java 的Object类
1.toString()是Objectde的方法,如果不重写,直接输出对象或者用对象调用toString()输出是会输出包名.类名@对象哈希码的无符号十六进制表示 子类如果重写了这个方法,可以隐式调用 ...
- bzoj4010: [HNOI2015]菜肴制作【拓扑排序】
想到了一个分治方法,每一次尽量放小的那个,把它依赖的放在左边,不依赖的放在右边. TLE 80: #include <bits/stdc++.h> #define rep(i, a, b) ...
- 关于IP选项
源:关于IP选项 校验和算法
- 【Xilinx-Petalinux学习】-03-PetaLinux通过eMMC方式启动
前面说的我的硬件上有一颗eMMC的芯片,型号是MTFC4GACAJCN-4M IT,有4GB的容量. BOOT.bin的文件较小,只有不到3MB,但是image.ub的文件根据不同的需求,将来可能会越 ...
- scala系列--基础语法
Scala 与 Java 的最大区别是:Scala 语句末尾的分号 ; 是可选的. 区分大小写 - Scala是大小写敏感的,这意味着标识Hello 和 hello在Scala中会有不同的含义. 类 ...