[codeforces]750C
来源:互联网 发布:琼州海峡隧道 知乎 编辑:程序博客网 时间:2024/04/29 02:51
time limit per test : 2 seconds
memory limit per test : 256 megabytes
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
The i-th of next n lines contains two integers ci and
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.
Input1
3-7 15 28 2
Output1
1907
Input2
257 122 2
Output2
Impossible
Input3
1-5 1
Output3
Infinity
Input4
427 213 1-50 18 2
Output4
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.
题意:
某人参加了n次cf比赛,ci为每次参赛的rating 变化,di为每次参赛的div。问其最后参加完n次比赛的rating最多是多少,无限大则输出Infinity,不存在则输出Impossible
题解:
二分,记住考虑起始rating 可能为负数…
#include<bits/stdc++.h>#define LiangJiaJun main#define INF 199912270000LL#define ll long longusing namespace std;int n;int c[200004],d[200004];ll ans;int check(ll x){ ll rating=x; for(int i=1;i<=n;i++){ if(rating>=1900&&d[i]==2)return 1; if(rating< 1900&&d[i]==1)return -1; rating += c[i]; } ans=rating; return 0;}int LiangJiaJun(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d%d",&c[i],&d[i]); ll l=-INF,r=INF,mid; ans=-INF; while(l<=r){ mid=(l+r)>>1; int k=check(mid); if(k==1)r=mid-1; else l=mid+1; } if(ans+100LL*200000>=INF)return puts("Infinity"),0; if(ans==-INF)return puts("Impossible"),0; printf("%d\n",ans); return 0;}
- codeforces-750【C思维】
- [codeforces]750C
- codeforces contest 750 c题
- 【codeforces 750C】New Year and Rating
- codeforces 750C New Year and Rating
- CodeForces - 750C(约束上下界)
- Codeforces 750 C New Year and Rating
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- codeforces 242C
- java文件流和管道流
- 使用alljoyn ios设备之间传输文件
- 免费发布信息网站有哪些?
- 关于使用idea工具debug时,断点颜色由红色变成灰色
- Unity中无法播放Animation问题
- [codeforces]750C
- 手把手教你Chrome浏览器安装Postman(含下载链接)
- MAC OS X下查看端口和杀死进程
- 浅谈Redis集群的架构与搭建
- iPhone旋转
- mybatis自连接
- 串的模式匹配算法
- Spark踩坑记——数据库(Hbase+Mysql)
- 匿名函数