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;
using ll = long long;
using pii = pair<ll,ll>;
const int MAXN = 500005;
vector<pii> G;
ll DP[2][MAXN];
bool vis[2][MAXN];
int n;
ll dp(int st, int id) {
if(id >= n) return 0;
else if(vis[st][id]) return DP[st][id];
vis[st][id] = true;
if(st == 0) {
DP[st][id] = max(G[id].second - (G[id].first - G[id-1].first),G[id].second - (G[id].first - G[id-1].first) + dp(0,id+1));
}
else {
DP[st][id] = max(G[id].second, G[id].second + dp(0,id+1));
}
return DP[st][id];
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
ll a, b;
while (cin >> n) {
G.clear();
memset(vis, 0, sizeof(vis));
for (int i = 0; i < n; ++i) {
cin >> a >> b;
G.push_back(make_pair(a,b));
}
sort(G.begin(), G.end());
ll res = G[0].second;
for (int i = 0; i < n; ++i) {
res = max(res, dp(1,i));
}
cout << res << '\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... |