CodeForces - 750C New Year and Rating

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 ≤ 1001 ≤ 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


题意: 题意很简单,一个n然后下面n行表示有n场比赛,c ji c表示这一场比赛所得到的分数,ji表示他在比赛开始之前所处的级别,一共有2

个级别,第一级别: >=1900分 第二级别: <=1899分;

问最后n场比赛比完,此人最多可得到多少分,没有最高分则输出Infinity 中间有冲突则输出Impossible。


思路:其实是一个数学题,很简单。设x为所得到的分数 拿第一个样例来讲,-7 1 表示x>=1900 第二次 5 2 表示 x-7<=1899 所以x<=1906

第三次 8 2 表示 x-7+5<=1899 得到x<=1901 所以直到最后一场比赛,,我们可以拿到n个不等式然后取交集 得到1900<=x<=1901 所以可以得到最后一场1901+-7+5+8 最大为1907.但是如果没有交集的话,就是不可能的情况,输出Impossible 如果右边界为极大值inf 则输出最大。


代码:


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
 #define N 200005
 #define inf 0x3f3f3f3f
 
 using namespace std;
 
 struct node
 {
 	int left,right;
 }a[N];
 
 int main()
 {
 	int n;
 	int i,j,x,ji;
 	scanf("%d",&n);
 	int pre=-1;
 	scanf("%d %d",&x,&ji);
 	for(i=1;i<=n;i++)
 	{
 		a[i].left=-inf;
 		a[i].right=inf;
	 }
 	if(ji==1)
 	{
 		a[1].left=1900;
	}
	else
	{
		a[1].right=1899;
	}
	pre=x;
	for(i=2;i<=n;i++)
 	{
 		scanf("%d %d",&x,&ji);
 		if(ji==1)
 		{
 			a[i].left=1900-pre;
		}
		else
		{
			a[i].right=1899-pre;
		}
		pre+=x;
	}
	int minn=inf;
	int maxx=-inf;
	for(i=1;i<=n;i++)
	{
		minn=min(minn,a[i].right);
		maxx=max(maxx,a[i].left);
	}
	//printf("%d %d\n",maxx,minn);
	int f=0;
	if(minn<maxx) f=1;
	if(f) printf("Impossible\n");
	else
	{
		if(minn==inf) printf("Infinity\n");
		else printf("%d\n",minn+pre);
	}
	return 0;
 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值