Advertisement
aayyk

Untitled

Feb 7th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. #include <stack>
  8. #include <climits>
  9. #include <string>
  10. #include <set>
  11. #include <cmath>
  12. #include <map>
  13. #include <unordered_map>
  14. #include <numeric>
  15. #include <random>
  16. #include <memory>
  17. #include <chrono>
  18. #include <iterator>
  19. #include <functional>
  20. #ifdef LOCAL
  21. #include "debug.h"
  22. #else
  23. #define debug(x...)
  24. #endif
  25. //#pragma GCC optimize("Ofast")
  26.  
  27. using namespace std;
  28. typedef long long ll;
  29. typedef long double ld;
  30. typedef pair <int, int> pii;
  31. #define mp make_pair
  32. #define pb push_back
  33. #define sz(x) int((x).size())
  34.  
  35. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  36. const int N = 1e5 + 7;
  37. const int inf = INT_MAX / 2;
  38. const ll INF = LLONG_MAX / 3;
  39. const int MOD = 998244353;
  40. const ld eps = 1e-6;
  41. const string cars[] = {"🚗", "🚕", "🚙"};
  42.  
  43.  
  44. signed main() {
  45. #ifdef LOCAL
  46.     freopen("input.txt", "r", stdin);
  47.     freopen("output.txt", "w", stdout);
  48. #endif
  49.     cout << fixed << setprecision(3);
  50.     cin.tie();
  51.     cout.tie();
  52.  
  53.     ll n, ans = 0, c = 0;
  54.     cin >> n;
  55.     vector < pair < ll, ll > > a(n);
  56.     vector < ll > p(n + 1);
  57.  
  58.     for (auto& [x, y] : a) {
  59.         cin >> x >> y;
  60.     }
  61.  
  62.     sort(a.begin(), a.end());
  63.  
  64.     for (int i = 0; i < n; i++) {
  65.         p[i + 1] = p[i] + a[i].first;
  66.     }
  67.     debug(p);
  68.  
  69.     for (int i = n - 1; i >= 0; i--) {
  70.         debug(a[i].first, p[i] + c);
  71.         if (a[i].first >= p[i] + c) {
  72.             ll x = ((a[i].first - (p[i] + c)) / 2 + 1);
  73.             debug(x);
  74.             ans += a[i].second * x;
  75.             c += x;
  76.         }
  77.     }
  78.    
  79.     cout << ans;
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement