fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int n;
  9. cin >> n;
  10.  
  11. vector<pair<int, int>> contests(n);
  12. for (int i = 0; i < n; ++i) {
  13. cin >> contests[i].first >> contests[i].second;
  14. }
  15.  
  16. long long minRating = 0;
  17. long long maxRating = 0;
  18. bool isInfinity = false;
  19.  
  20. for (int i = 0; i < n; ++i) {
  21. int ci = contests[i].first;
  22. int di = contests[i].second;
  23.  
  24. if (di == 1) {
  25. minRating = max(minRating, 1900LL);
  26. maxRating += ci;
  27. if (maxRating < 1900) {
  28. cout << "Impossible" << endl;
  29. return 0;
  30. }
  31. } else {
  32. minRating += ci;
  33. maxRating += ci;
  34. if (maxRating < 1900) {
  35. if (minRating < 1900) {
  36. cout << "Impossible" << endl;
  37. return 0;
  38. }
  39. }
  40. }
  41.  
  42. if (maxRating >= 1900 && minRating >= 1900) {
  43. isInfinity = true;
  44. }
  45. }
  46.  
  47. if (isInfinity) {
  48. cout << "Infinity" << endl;
  49. } else {
  50. cout << maxRating << endl;
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 5284KB
stdin
3
-7 1
5 2
8 2
stdout
Impossible