Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- typedef long long ll;
- int main() {
- int n;
- cin >> n;
- vector<pair<ll, ll>> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i].second >> v[i].first;
- }
- sort(v.begin(), v.end());
- int i = 0, j = n - 1;
- ll res = 0;
- int L = 0, R = 0;
- while(i <= j) {
- res = max(res, v[i].first + v[j].first);
- L++;
- R++;
- if(L > v[i].second) {
- i++;
- L = 0;
- }
- if(R > v[j].second) {
- j--;
- R = 0;
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement