New Year and Rating
题目链接
题目
样例
输入
3
-7 1
5 2
8 2
输出
1907
思路
二分
二分rating,从1到n遍历,若碰到不满足条件的:1却max小于1900,2却min大于1899,则直接返回,修改mid的区间重新取
若满足条件,则直接加减所给值
模拟
和上面一样,若不满足直接输出,满足则一直加
代码
点击查看代码
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <vector>
#include <cstring>
#include <bitset>
#include <set>using namespace std;
using ll = long long;
ll ma = 2e8 + 10;
int mi;int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int lcm(int a, int b) {return a / gcd(a, b) * b;}void solve()
{int n; cin >> n;while(n--) {int a, b; cin >> a >> b;if((b == 1 && ma < 1900) || (b == 2 && mi > 1899)) {cout << "Impossible";return;}if(b == 1 && mi < 1900) mi = 1900;if(b == 2 && ma > 1899) ma = 1899;if(mi != 0) mi += a;if(ma != 2e8 + 10) ma += a;}if(ma == 2e8 + 10) cout << "Infinity";else cout << ma;
}int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);//int t; cin >> t;int t = 1;while (t--) solve();
}