This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<pair<long long,long long>> vec(N+1);
for(int i = 1;i<=N;++i) cin >> vec[i].first >> vec[i].second; //first is size, second is value
sort(vec.begin(),vec.end()); //sorted by size
vector<long long> pref(N+1); pref[0] = 0;
for(int i = 1;i<=N;++i) pref[i] = pref[i-1]+vec[i].second; //prefix sums on value
long long cur = vec[1].first, ans = 0;
for(int i = 1;i<=N;++i){
cur = max(cur,vec[i].first-pref[i-1]);
ans = max(ans,pref[i]-vec[i].first+cur);
cout << cur << " " << ans << "\n";
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |