Advertisement
Josif_tepe

Untitled

Sep 27th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <algorithm>
  5. #include <fstream>
  6. using namespace std;
  7. typedef long long ll;
  8. int main() {
  9.  
  10.     int n;
  11.     cin >> n;
  12.    
  13.     vector<pair<ll, ll>> v(n);
  14.     for(int i = 0; i < n; i++) {
  15.         cin >> v[i].second >> v[i].first;
  16.     }
  17.     sort(v.begin(), v.end());
  18.     int i = 0, j = n - 1;
  19.     ll res = 0;
  20.     int L = 0, R = 0;
  21.     while(i <= j) {
  22.         res = max(res, v[i].first + v[j].first);
  23.         L++;
  24.         R++;
  25.        
  26.         if(L > v[i].second) {
  27.             i++;
  28.             L = 0;
  29.         }
  30.         if(R > v[j].second) {
  31.             j--;
  32.             R = 0;
  33.         }
  34.     }
  35.     cout << res << endl;
  36.    
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement