国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

CodeForces - 750C(約束上下界)

2019-11-08 18:23:23
字體:
供稿:網(wǎng)友

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 n contests.

Example 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.


給出打每場比賽前的等級和這場比賽的得分情況,要求求出最終總分?jǐn)?shù)的最大值,因?yàn)榈燃壱挥邢陆?900,等級二有上界1899,所以初始化初始得分的上下界后,每一次比賽前的等級就可以幫助我們根據(jù)之前的得分情況約束上界或者下界,如果位于等級1就約束下界,位于等級二就約束上界,最終如果上界沒被約束過答案就是inf,如果下界比上界還大就是impossible,不然就輸出上界+每場得分。

#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<string>#include<map>#include<set>#include<vector>using namespace std;int dd[200005];int l[200005];int n;int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d%d",&dd[i],&l[i]); } int up,down; if(l[0]==2){down=-30000000;up=1899;} else{down=1900;up=30000000;} int cnt=0; for(int i=1;i<n;i++){ cnt+=dd[i-1]; if(l[i]==1){ if(down+cnt<1900){down=1900-cnt;} } else{ if(up+cnt>1899){up=1899-cnt;} } } int ans; if(up==30000000){printf("Infinity/n");} else if(down>up){printf("Impossible/n");} else{ ans=up; for(int i=0;i<n;i++){ans+=dd[i];} printf("%d/n",ans); }return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 建宁县| 叶城县| 华宁县| 页游| 清新县| 绥阳县| 乌兰浩特市| 布拖县| 崇左市| 建宁县| 莱阳市| 临汾市| 无为县| 巩义市| 荆门市| 马山县| 东城区| 肥城市| 莎车县| 武穴市| 博乐市| 夹江县| 长汀县| 山阳县| 阜阳市| 麟游县| 福建省| 巴中市| 临汾市| 承德县| 南京市| 德安县| 谷城县| 区。| 屏山县| 上犹县| 涟源市| 涿州市| 赣州市| 巢湖市| 德惠市|