danielvitor23

Esteira

Nov 2nd, 2021 (edited)
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, a, d;
  5.  
  6. int main() {
  7.   cin.tie(0)->sync_with_stdio(0);
  8.   cin >> n;
  9.   bool waiting = false;
  10.   int last = 0, curr = -1;
  11.   for (int i = 0; i < n; ++i) {
  12.     cin >> a >> d;
  13.     if (a > last and waiting) {
  14.       last += 10;
  15.       curr ^= 1;
  16.       waiting = false;
  17.     }
  18.     if (a > last) {
  19.       last = a + 10;
  20.       curr = d;
  21.     } else if (a < last) {
  22.       if (curr != d) {
  23.         waiting = true;
  24.       } else {
  25.         last = a + 10;
  26.       }
  27.     }
  28.   }
  29.   if (waiting) last += 10;
  30.   cout << last << '\n';
  31. }
  32. /*
  33. 6
  34. 5 0
  35. 9 0
  36. 10 1
  37. 11 1
  38. 12 0
  39. 15 0
  40. R = 35
  41.  
  42. 7
  43. 5 0
  44. 9 0
  45. 10 1
  46. 11 1
  47. 12 0
  48. 15 0
  49. 24 1
  50. R = 35
  51.  
  52. 7
  53. 5 0
  54. 9 0
  55. 10 1
  56. 11 1
  57. 12 0
  58. 15 0
  59. 26 1
  60. R = 36
  61.  
  62. 4
  63. 5 0
  64. 7 1
  65. 14 0
  66. 15 0
  67. R = 35
  68.  
  69. 4
  70. 5 0
  71. 8 0
  72. 10 1
  73. 13 0
  74. R = 33
  75.  
  76. */
Add Comment
Please, Sign In to add comment