#include <bits/stdc++.h>
using namespace std;
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;
void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}
const int maxn = 500050;
int n;
ll suf[maxn];
struct pic{ll a; ll s;}g[maxn];
bool cmp(pic a, pic b){return a.a < b.a;}
int main()
{
#ifdef MPS
fp("1.in","r",stdin);
fp("1.out","w",stdout);
#endif
sf("%d",&n);
fo(i,1,n) sf("%lld%lld",&g[i].a,&g[i].s);
sort(g+1,g+n+1,cmp);
fo(i,1,n) g[i].s += g[i-1].s;
suf[n+1] = -INF;
fd(i,n,1) suf[i] = max(suf[i+1], g[i].s - g[i].a);
ll ans = 0; fo(i,1,n) ans = max(ans, g[i].a - g[i-1].s + suf[i]);
pf("%lld",ans);
return 0;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:46:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
sf("%d",&n);
^
art.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fo(i,1,n) sf("%lld%lld",&g[i].a,&g[i].s);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
32 ms |
504 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
29 |
Correct |
4 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
632 KB |
Output is correct |
33 |
Correct |
4 ms |
536 KB |
Output is correct |
34 |
Correct |
4 ms |
632 KB |
Output is correct |
35 |
Correct |
4 ms |
632 KB |
Output is correct |
36 |
Correct |
4 ms |
504 KB |
Output is correct |
37 |
Correct |
4 ms |
632 KB |
Output is correct |
38 |
Correct |
4 ms |
632 KB |
Output is correct |
39 |
Correct |
4 ms |
632 KB |
Output is correct |
40 |
Correct |
4 ms |
504 KB |
Output is correct |
41 |
Correct |
4 ms |
508 KB |
Output is correct |
42 |
Correct |
4 ms |
632 KB |
Output is correct |
43 |
Correct |
4 ms |
504 KB |
Output is correct |
44 |
Correct |
4 ms |
508 KB |
Output is correct |
45 |
Correct |
4 ms |
504 KB |
Output is correct |
46 |
Correct |
4 ms |
632 KB |
Output is correct |
47 |
Correct |
4 ms |
632 KB |
Output is correct |
48 |
Correct |
4 ms |
632 KB |
Output is correct |
49 |
Correct |
4 ms |
532 KB |
Output is correct |
50 |
Correct |
4 ms |
632 KB |
Output is correct |
51 |
Correct |
4 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
32 ms |
504 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
29 |
Correct |
4 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
632 KB |
Output is correct |
33 |
Correct |
4 ms |
536 KB |
Output is correct |
34 |
Correct |
4 ms |
632 KB |
Output is correct |
35 |
Correct |
4 ms |
632 KB |
Output is correct |
36 |
Correct |
4 ms |
504 KB |
Output is correct |
37 |
Correct |
4 ms |
632 KB |
Output is correct |
38 |
Correct |
4 ms |
632 KB |
Output is correct |
39 |
Correct |
4 ms |
632 KB |
Output is correct |
40 |
Correct |
4 ms |
504 KB |
Output is correct |
41 |
Correct |
4 ms |
508 KB |
Output is correct |
42 |
Correct |
4 ms |
632 KB |
Output is correct |
43 |
Correct |
4 ms |
504 KB |
Output is correct |
44 |
Correct |
4 ms |
508 KB |
Output is correct |
45 |
Correct |
4 ms |
504 KB |
Output is correct |
46 |
Correct |
4 ms |
632 KB |
Output is correct |
47 |
Correct |
4 ms |
632 KB |
Output is correct |
48 |
Correct |
4 ms |
632 KB |
Output is correct |
49 |
Correct |
4 ms |
532 KB |
Output is correct |
50 |
Correct |
4 ms |
632 KB |
Output is correct |
51 |
Correct |
4 ms |
632 KB |
Output is correct |
52 |
Correct |
232 ms |
24664 KB |
Output is correct |
53 |
Correct |
229 ms |
24728 KB |
Output is correct |
54 |
Correct |
227 ms |
24780 KB |
Output is correct |
55 |
Correct |
232 ms |
24696 KB |
Output is correct |
56 |
Correct |
229 ms |
24736 KB |
Output is correct |
57 |
Correct |
232 ms |
24836 KB |
Output is correct |
58 |
Correct |
229 ms |
24668 KB |
Output is correct |
59 |
Correct |
228 ms |
24696 KB |
Output is correct |
60 |
Correct |
230 ms |
24696 KB |
Output is correct |
61 |
Correct |
235 ms |
24568 KB |
Output is correct |
62 |
Correct |
232 ms |
24696 KB |
Output is correct |
63 |
Correct |
230 ms |
24660 KB |
Output is correct |
64 |
Correct |
233 ms |
24748 KB |
Output is correct |
65 |
Correct |
231 ms |
24680 KB |
Output is correct |
66 |
Correct |
231 ms |
24616 KB |
Output is correct |
67 |
Correct |
232 ms |
24820 KB |
Output is correct |
68 |
Correct |
227 ms |
24608 KB |
Output is correct |