Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool isDiag = false;
- vector<pair<int,int>> listV ;
- int main(){
- //isDiag = true;
- freopen("pairup.in", "r", stdin);
- int n;
- cin >> n ;
- int x, y;
- if(isDiag) cout << "n: " << n << endl;
- for (int i = 0; i < n; i++)
- {
- cin >> x >> y;
- listV.push_back({y,x});
- }
- sort(listV.begin(), listV.end());
- int N = 0;
- int X = n-1;
- long ans = 0;
- while (N <= X)
- {
- long va = listV[N].first + listV[X].first;
- int burn = min(listV[N].second, listV[X].second); // must optimze burn for batch operation
- listV[N].second = listV[N].second - burn;
- if (listV[N].second == 0)
- {
- N++;
- }
- listV[X].second = listV[X].second - burn;
- if (listV[X].second == 0)
- {
- X--;
- }
- ans = max( ans, va);
- if (isDiag) cout << "N: " << N << ", X: " << X << "burn: " << burn << ", va: " << va << ", ans: " << ans << endl;
- }
- if (!isDiag) freopen("pairup.out", "w", stdout);
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement