Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #define ll long long
- using namespace std;
- int main()
- {
- ll n, V=0;
- cin>>n;
- vector< pair<ll, ll> > v;
- ll x, y;
- for(ll i=0; i<n; i++)
- {
- cin>>x>>y;
- v.push_back( {y,x} );
- V+=x;
- }
- sort(v.begin(), v.end());
- /**for(ll i=0; i<v.size(); i++)
- cout<<v[i].first<<"-"<<v[i].second<<" ";
- cout<<endl;**/
- ll ini=0;
- ll fin=v.size()-1;
- ll suma, may=(-1);
- for(ll i=0; i<V/2; i++)
- {
- /*if (ini<0 || ini >=v.size())
- cout<<"ERROR";
- if (fin<0 || fin >=v.size())
- cout<<"ERROR";*/
- suma = v[ini].first + v[fin].first;
- if (suma > may)
- may = suma;
- v[ini].second--;
- v[fin].second--;
- if (v[ini].second == 0)
- ini++;
- if (v[fin].second == 0)
- fin--;
- }
- cout<<may;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment