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;
typedef long long ll;
#define PUB push_back
struct art{
ll sz, val;
};
int N;
ll ans = 0, cnt = 0, pref[500005];
vector<art> data;
bool comp(art a, art b){
if(a.sz == b.sz) return a.val < b.val;
return a.sz < b.sz;
}
ll optimized(){
cnt += data[1].val;
ans = max(cnt, ans);
for(int i=2;i<=N;i++){
cnt += data[i].val-(data[i].sz-data[i-1].sz);
if(cnt <= 0 || cnt < data[i].val){
cnt = data[i].val;
}
ans = max(ans, cnt);
}
}
ll bf(){
cout << "== BF ==" << endl;
for(int i=1;i<=N;i++) pref[i] = pref[i-1]+data[i].val;
for(int i=1;i<=N;i++) for(int j=i;j<=N;j++){
ll tmp = (pref[j]-pref[i-1])-(data[j].sz-data[i].sz);
if(ans < tmp){
cout << i << " " << j << " " << tmp << endl;
ans = tmp;
}
}
}
int main(){
cin >> N;
data.PUB({0,0});
for(int i=1;i<=N;i++){
ll a, b;
cin >> a >> b;
data.PUB({a, b});
}
sort(data.begin(), data.end(), comp);
optimized();
cout << ans << endl;
//bf();
//cout << ans << endl;
}
Compilation message (stderr)
art.cpp: In function 'll optimized()':
art.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
art.cpp: In function 'll bf()':
art.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# | 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... |