// -*- compile-command: "g++ -g -Wno-return-type -Wall -Wextra -DLOCAL -std=c++17 -D_GLIBCXX_DEBUG art.cpp -oart && ./art " -*-
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define int LL
#define vc vector
#define pb push_back
#define pr pair
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define f(i,n) for(int i=0;i<(n);i++)
#define fv(i,v) f(i,sz(v))
struct S{ int a,b; };
main(){
ios::sync_with_stdio(0),cin.tie(0);
int n;
cin>>n;
vc<S> art(n);
f(i,n) cin>>art[i].a>>art[i].b;
sort(all(art),[](S x,S y){ return x.a>y.a; });
vc<int> p(n+1);
f(i,n) p[i+1]=p[i]+art[i].b;
int best=0;
int low=art[0].a;
f(i,n+1){
if(i) best=max(best,p[i]+art[i-1].a-low);
if(i<n) low=min(low,p[i]+art[i].a);
}
cout<<best<<'\n';
}
Compilation message
art.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
264 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
264 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
264 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
3 ms |
520 KB |
Output is correct |
29 |
Correct |
2 ms |
508 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
3 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
3 ms |
460 KB |
Output is correct |
35 |
Correct |
3 ms |
504 KB |
Output is correct |
36 |
Correct |
2 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
460 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
3 ms |
460 KB |
Output is correct |
40 |
Correct |
2 ms |
452 KB |
Output is correct |
41 |
Correct |
2 ms |
460 KB |
Output is correct |
42 |
Correct |
3 ms |
460 KB |
Output is correct |
43 |
Correct |
3 ms |
460 KB |
Output is correct |
44 |
Correct |
3 ms |
460 KB |
Output is correct |
45 |
Correct |
3 ms |
460 KB |
Output is correct |
46 |
Correct |
3 ms |
460 KB |
Output is correct |
47 |
Correct |
3 ms |
460 KB |
Output is correct |
48 |
Correct |
3 ms |
460 KB |
Output is correct |
49 |
Correct |
3 ms |
460 KB |
Output is correct |
50 |
Correct |
3 ms |
460 KB |
Output is correct |
51 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
264 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
3 ms |
520 KB |
Output is correct |
29 |
Correct |
2 ms |
508 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
3 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
3 ms |
460 KB |
Output is correct |
35 |
Correct |
3 ms |
504 KB |
Output is correct |
36 |
Correct |
2 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
460 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
3 ms |
460 KB |
Output is correct |
40 |
Correct |
2 ms |
452 KB |
Output is correct |
41 |
Correct |
2 ms |
460 KB |
Output is correct |
42 |
Correct |
3 ms |
460 KB |
Output is correct |
43 |
Correct |
3 ms |
460 KB |
Output is correct |
44 |
Correct |
3 ms |
460 KB |
Output is correct |
45 |
Correct |
3 ms |
460 KB |
Output is correct |
46 |
Correct |
3 ms |
460 KB |
Output is correct |
47 |
Correct |
3 ms |
460 KB |
Output is correct |
48 |
Correct |
3 ms |
460 KB |
Output is correct |
49 |
Correct |
3 ms |
460 KB |
Output is correct |
50 |
Correct |
3 ms |
460 KB |
Output is correct |
51 |
Correct |
3 ms |
460 KB |
Output is correct |
52 |
Correct |
212 ms |
24632 KB |
Output is correct |
53 |
Correct |
214 ms |
24640 KB |
Output is correct |
54 |
Correct |
209 ms |
24616 KB |
Output is correct |
55 |
Correct |
210 ms |
24640 KB |
Output is correct |
56 |
Correct |
207 ms |
24640 KB |
Output is correct |
57 |
Correct |
210 ms |
24640 KB |
Output is correct |
58 |
Correct |
210 ms |
24624 KB |
Output is correct |
59 |
Correct |
208 ms |
24628 KB |
Output is correct |
60 |
Correct |
206 ms |
24640 KB |
Output is correct |
61 |
Correct |
208 ms |
24488 KB |
Output is correct |
62 |
Correct |
207 ms |
24644 KB |
Output is correct |
63 |
Correct |
208 ms |
24580 KB |
Output is correct |
64 |
Correct |
215 ms |
24624 KB |
Output is correct |
65 |
Correct |
207 ms |
24644 KB |
Output is correct |
66 |
Correct |
206 ms |
24628 KB |
Output is correct |
67 |
Correct |
218 ms |
24624 KB |
Output is correct |
68 |
Correct |
209 ms |
24644 KB |
Output is correct |