이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |