danielvitor23

Untitled

Nov 1st, 2021 (edited)
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void __print(int x) {cerr << x;}
  5. void __print(long x) {cerr << x;}
  6. void __print(long long x) {cerr << x;}
  7. void __print(unsigned x) {cerr << x;}
  8. void __print(unsigned long x) {cerr << x;}
  9. void __print(unsigned long long x) {cerr << x;}
  10. void __print(float x) {cerr << x;}
  11. void __print(double x) {cerr << x;}
  12. void __print(long double x) {cerr << x;}
  13. void __print(char x) {cerr << '\'' << x << '\'';}
  14. void __print(const char *x) {cerr << '\"' << x << '\"';}
  15. void __print(const string &x) {cerr << '\"' << x << '\"';}
  16. void __print(bool x) {cerr << (x ? "true" : "false");}
  17.  
  18. template<typename T, typename V>
  19. void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  20. template<typename T>
  21. void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  22. void _print() {cerr << "]\n";}
  23. template <typename T, typename... V>
  24. void print(T t, V... v) {_print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  25. #ifndef ONLINE_JUDGE
  26. #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
  27. #else
  28. #define debug(x...)
  29. #endif
  30.  
  31. #define len(v) (int)(v).size()
  32. #define all(v) (v).begin(),(v).end()
  33. #define forn(i, n) for (int i=0;i<n;++i)
  34.  
  35. using val = int64_t;
  36. using ii = pair<val,int>;
  37.  
  38. const char nl = '\n';
  39. const int mod = 1000000007;
  40.  
  41. int main() {
  42.   cin.tie(nullptr)->sync_with_stdio(false);
  43.  
  44.   int n;
  45.   cin >> n;
  46.   deque<val> a, b;
  47.   forn (i, n) {
  48.     val x;
  49.     int dir;
  50.     cin >> x >> dir;
  51.     if (dir) a.push_back(x);
  52.     else b.push_back(x);
  53.   }
  54.   val tempo = 0;
  55.   while (!(a.empty() && b.empty())) {
  56.     if (a.empty()) {
  57.       if (tempo < b.front()) {
  58.     tempo = b.front();
  59.       }
  60.       val q = b.front();
  61.       b.pop_front();
  62.       while (!b.empty() && q < tempo) {
  63.     q = b.front();
  64.     b.pop_front();
  65.       }
  66.       if (q < tempo) {
  67.     tempo += 10;
  68.       } else {
  69.     if (!b.empty()) {
  70.       tempo += b.back() - q + 10;
  71.     } else {
  72.       tempo += 10;
  73.     }
  74.       }
  75.       break;
  76.     } else if (b.empty()) {
  77.       if (tempo < a.front()) {
  78.     tempo = a.front();
  79.       }
  80.       val q = a.front();
  81.       a.pop_front();
  82.       while (!a.empty() && q < tempo) {
  83.     q = a.front();
  84.     a.pop_front();
  85.       }
  86.       if (q < tempo) {
  87.     tempo += 10;
  88.       } else {
  89.     if (!a.empty()) {
  90.       tempo += a.back() - q + 10;
  91.     } else {
  92.       tempo += 10;
  93.     }
  94.       }
  95.       break;
  96.     } else {
  97.       if (a.front() < b.front()) {
  98.     val q = a.front();
  99.     a.pop_front();
  100.     val diff = 0;
  101.     if (tempo < q) {
  102.       tempo = q;
  103.     }
  104.     while (!a.empty() && a.front() - q <= 10) {
  105.       diff += max(a.front() - max(tempo, q), (val)0);
  106.       q = a.front();
  107.       a.pop_front();
  108.     }
  109.     tempo += 10 + diff;
  110.       } else {
  111.     val q = b.front();
  112.     b.pop_front();
  113.     val diff = 0;
  114.     if (tempo < q) {
  115.       tempo = q;
  116.     }
  117.     while (!b.empty() && b.front() - q <= 10) {
  118.       diff += max(b.front() - max(tempo, q), (val)0);
  119.       q = b.front();
  120.       b.pop_front();
  121.     }
  122.     tempo += 10 + diff;
  123.       }
  124.     }
  125.   }
  126.  
  127.   cout << tempo << nl;
  128.  
  129.  
  130.   return 0;
  131. }
Add Comment
Please, Sign In to add comment