zoukankan      html  css  js  c++  java
  • C. 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 ≤ 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.

    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.

    /*
    给出每次的上的分和降的分,和相应的等级,让你输出最后的分数,不可能输出impossible。可以是正无穷的话Infinity,否则输出最大的.
    
    初步思路:建立两个边界,从第一条开始遍历,根据条件放缩,到最后如果最大边界不确定,就是正无穷,左边界大于有边界就是不可能,否则输出有边界
    
    #反思:比赛的时候放缩的时候想的太复杂了。分情况的时候取大取小没考虑好
           好在有惊无险的上分了,离紫色又进了一步
    */
    #include<bits/stdc++.h>
    #define INF 300000000
    using namespace std;
    long long n;
    long long a,b;
    long long l,r;
    int main(){
        //freopen("in.txt","r",stdin);
        cin>>n;
        l=-INF,r=INF;//判断的两个边
        for(int i=0;i<n;i++){
            cin>>a>>b;
            if(b==1&&l<1900) l=1900;//当前是第一阶段,如果本来的边界有小于1900的,那么不满足,必须放缩到1900
            if(b==2&&r>1899) r=1899;
            l+=a;
            r+=a;
        }
        long long cur=max(l,r);
        if(l>r) puts("Impossible");
        else if(cur>200000000) puts("Infinity");//就算2000000次都上分,那么最大也只可能是200000000
        else cout<<cur<<endl;
        return 0;
    }
  • 相关阅读:
    poj 3304 直线与线段相交
    poj 2318 叉积+二分
    AC自动机
    MySQL报错:Packets larger than max_allowed_packet are not allowed 的解决方案
    SCOPE_IDENTITY的作用
    Truncate table、Delete与Drop table的区别
    .Net Attribute特性
    vs2010 调试快捷键
    TFS和VSS的简单对比
    做网站用UTF-8还是GB2312 & 各国语言对应字符集
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6239075.html
Copyright © 2011-2022 走看看