#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 |
1 |
Correct |
3 ms |
1400 KB |
Output is correct |
2 |
Correct |
3 ms |
1400 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1312 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1400 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1400 KB |
Output is correct |
11 |
Correct |
3 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1400 KB |
Output is correct |
2 |
Correct |
3 ms |
1400 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1312 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1400 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1400 KB |
Output is correct |
11 |
Correct |
3 ms |
1400 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
3 ms |
1400 KB |
Output is correct |
14 |
Correct |
3 ms |
1404 KB |
Output is correct |
15 |
Correct |
3 ms |
1400 KB |
Output is correct |
16 |
Correct |
3 ms |
1400 KB |
Output is correct |
17 |
Correct |
3 ms |
1400 KB |
Output is correct |
18 |
Correct |
3 ms |
1400 KB |
Output is correct |
19 |
Correct |
3 ms |
1404 KB |
Output is correct |
20 |
Correct |
3 ms |
1400 KB |
Output is correct |
21 |
Correct |
3 ms |
1400 KB |
Output is correct |
22 |
Correct |
3 ms |
1400 KB |
Output is correct |
23 |
Correct |
3 ms |
1400 KB |
Output is correct |
24 |
Correct |
3 ms |
1400 KB |
Output is correct |
25 |
Correct |
10 ms |
1400 KB |
Output is correct |
26 |
Correct |
3 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1400 KB |
Output is correct |
2 |
Correct |
3 ms |
1400 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1312 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1400 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1400 KB |
Output is correct |
11 |
Correct |
3 ms |
1400 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
3 ms |
1400 KB |
Output is correct |
14 |
Correct |
3 ms |
1404 KB |
Output is correct |
15 |
Correct |
3 ms |
1400 KB |
Output is correct |
16 |
Correct |
3 ms |
1400 KB |
Output is correct |
17 |
Correct |
3 ms |
1400 KB |
Output is correct |
18 |
Correct |
3 ms |
1400 KB |
Output is correct |
19 |
Correct |
3 ms |
1404 KB |
Output is correct |
20 |
Correct |
3 ms |
1400 KB |
Output is correct |
21 |
Correct |
3 ms |
1400 KB |
Output is correct |
22 |
Correct |
3 ms |
1400 KB |
Output is correct |
23 |
Correct |
3 ms |
1400 KB |
Output is correct |
24 |
Correct |
3 ms |
1400 KB |
Output is correct |
25 |
Correct |
10 ms |
1400 KB |
Output is correct |
26 |
Correct |
3 ms |
1400 KB |
Output is correct |
27 |
Correct |
6 ms |
1912 KB |
Output is correct |
28 |
Correct |
6 ms |
2040 KB |
Output is correct |
29 |
Correct |
6 ms |
1912 KB |
Output is correct |
30 |
Correct |
6 ms |
1912 KB |
Output is correct |
31 |
Correct |
6 ms |
2040 KB |
Output is correct |
32 |
Correct |
6 ms |
2040 KB |
Output is correct |
33 |
Correct |
6 ms |
1912 KB |
Output is correct |
34 |
Correct |
6 ms |
1912 KB |
Output is correct |
35 |
Correct |
6 ms |
2040 KB |
Output is correct |
36 |
Correct |
6 ms |
2040 KB |
Output is correct |
37 |
Correct |
6 ms |
2040 KB |
Output is correct |
38 |
Correct |
6 ms |
1912 KB |
Output is correct |
39 |
Correct |
6 ms |
1916 KB |
Output is correct |
40 |
Correct |
6 ms |
2040 KB |
Output is correct |
41 |
Correct |
6 ms |
2040 KB |
Output is correct |
42 |
Correct |
6 ms |
1912 KB |
Output is correct |
43 |
Correct |
6 ms |
2040 KB |
Output is correct |
44 |
Correct |
6 ms |
2040 KB |
Output is correct |
45 |
Correct |
6 ms |
1980 KB |
Output is correct |
46 |
Correct |
5 ms |
2040 KB |
Output is correct |
47 |
Correct |
6 ms |
1912 KB |
Output is correct |
48 |
Correct |
6 ms |
2040 KB |
Output is correct |
49 |
Correct |
6 ms |
2040 KB |
Output is correct |
50 |
Correct |
6 ms |
1960 KB |
Output is correct |
51 |
Correct |
7 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1400 KB |
Output is correct |
2 |
Correct |
3 ms |
1400 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1312 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1400 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
3 ms |
1272 KB |
Output is correct |
10 |
Correct |
3 ms |
1400 KB |
Output is correct |
11 |
Correct |
3 ms |
1400 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
3 ms |
1400 KB |
Output is correct |
14 |
Correct |
3 ms |
1404 KB |
Output is correct |
15 |
Correct |
3 ms |
1400 KB |
Output is correct |
16 |
Correct |
3 ms |
1400 KB |
Output is correct |
17 |
Correct |
3 ms |
1400 KB |
Output is correct |
18 |
Correct |
3 ms |
1400 KB |
Output is correct |
19 |
Correct |
3 ms |
1404 KB |
Output is correct |
20 |
Correct |
3 ms |
1400 KB |
Output is correct |
21 |
Correct |
3 ms |
1400 KB |
Output is correct |
22 |
Correct |
3 ms |
1400 KB |
Output is correct |
23 |
Correct |
3 ms |
1400 KB |
Output is correct |
24 |
Correct |
3 ms |
1400 KB |
Output is correct |
25 |
Correct |
10 ms |
1400 KB |
Output is correct |
26 |
Correct |
3 ms |
1400 KB |
Output is correct |
27 |
Correct |
6 ms |
1912 KB |
Output is correct |
28 |
Correct |
6 ms |
2040 KB |
Output is correct |
29 |
Correct |
6 ms |
1912 KB |
Output is correct |
30 |
Correct |
6 ms |
1912 KB |
Output is correct |
31 |
Correct |
6 ms |
2040 KB |
Output is correct |
32 |
Correct |
6 ms |
2040 KB |
Output is correct |
33 |
Correct |
6 ms |
1912 KB |
Output is correct |
34 |
Correct |
6 ms |
1912 KB |
Output is correct |
35 |
Correct |
6 ms |
2040 KB |
Output is correct |
36 |
Correct |
6 ms |
2040 KB |
Output is correct |
37 |
Correct |
6 ms |
2040 KB |
Output is correct |
38 |
Correct |
6 ms |
1912 KB |
Output is correct |
39 |
Correct |
6 ms |
1916 KB |
Output is correct |
40 |
Correct |
6 ms |
2040 KB |
Output is correct |
41 |
Correct |
6 ms |
2040 KB |
Output is correct |
42 |
Correct |
6 ms |
1912 KB |
Output is correct |
43 |
Correct |
6 ms |
2040 KB |
Output is correct |
44 |
Correct |
6 ms |
2040 KB |
Output is correct |
45 |
Correct |
6 ms |
1980 KB |
Output is correct |
46 |
Correct |
5 ms |
2040 KB |
Output is correct |
47 |
Correct |
6 ms |
1912 KB |
Output is correct |
48 |
Correct |
6 ms |
2040 KB |
Output is correct |
49 |
Correct |
6 ms |
2040 KB |
Output is correct |
50 |
Correct |
6 ms |
1960 KB |
Output is correct |
51 |
Correct |
7 ms |
2040 KB |
Output is correct |
52 |
Correct |
309 ms |
53388 KB |
Output is correct |
53 |
Correct |
298 ms |
53288 KB |
Output is correct |
54 |
Correct |
296 ms |
53316 KB |
Output is correct |
55 |
Correct |
302 ms |
53204 KB |
Output is correct |
56 |
Correct |
298 ms |
53296 KB |
Output is correct |
57 |
Correct |
295 ms |
53332 KB |
Output is correct |
58 |
Correct |
301 ms |
53304 KB |
Output is correct |
59 |
Correct |
295 ms |
53328 KB |
Output is correct |
60 |
Correct |
295 ms |
53204 KB |
Output is correct |
61 |
Correct |
294 ms |
53292 KB |
Output is correct |
62 |
Correct |
293 ms |
53280 KB |
Output is correct |
63 |
Correct |
292 ms |
53336 KB |
Output is correct |
64 |
Correct |
293 ms |
53380 KB |
Output is correct |
65 |
Correct |
304 ms |
53204 KB |
Output is correct |
66 |
Correct |
290 ms |
53204 KB |
Output is correct |
67 |
Correct |
325 ms |
53432 KB |
Output is correct |
68 |
Correct |
294 ms |
53336 KB |
Output is correct |