#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define repd(i,a,b) for(int i = (a);i >= (b);i--)
#define PB push_back
#define F first
#define S second
#define Task ""
using namespace std;
template <class T> T read(T &a){a = 0;char c = cin.get();bool nega = 0;while(!isdigit(c) && c != '-')c = cin.get();if(c == '-')nega = 1,c = cin.get();a = c - 48;c = cin.get();while(isdigit(c))a = a * 10 + c - 48,c = cin.get();if(nega)a = -a;return a;}
template <class T> void writep(T a){if(a > 9)writep(a / 10);cout.put(a % 10 + 48);}
template <class T> void write(T a){if(a < 0)cout.put('-'),a = -a;writep(a);cout.put(' ');}
template <class T> void writeln(T a){write(a);cout.put('\n');}
const int N = 500012;
int n;
pair<long long,long long> a[N];
struct seg
{
long long t[4*N];
#define mid ((l + r)/2)
long long build(int l,int r,int id)
{
if(l == r) return t[id] = a[l].S - a[l].F;
return t[id] = max(build(l,mid,id*2),build(mid+1,r,id*2+1));
}
long long get(int l,int r,int id,int u,int v)
{
if(l > v || r < u) return LLONG_MIN;
if(l >= u && r <= v) return t[id];
return max(get(l,mid,id*2,u,v),get(mid+1,r,id*2+1,u,v));
}
}IT;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen(Task".inp","r",stdin);
// freopen(Task".out","w",stdout);
cin >> n;
rep(i,1,n)
cin >> a[i].F >> a[i].S;
sort(a+1,a+n+1);
rep(i,1,n) a[i].S += a[i-1].S;
long long ans = 0;
IT.build(1,n,1);
rep(i,1,n)
ans = max(ans,IT.get(1,n,1,i,n) + a[i].F - a[i-1].S);
cout << ans;
return 0;
}
# |
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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
12 ms |
404 KB |
Output is correct |
9 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
12 ms |
404 KB |
Output is correct |
9 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
12 ms |
404 KB |
Output is correct |
9 |
Correct |
2 ms |
380 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 |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
636 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
632 KB |
Output is correct |
33 |
Correct |
5 ms |
632 KB |
Output is correct |
34 |
Correct |
5 ms |
632 KB |
Output is correct |
35 |
Correct |
5 ms |
760 KB |
Output is correct |
36 |
Correct |
6 ms |
632 KB |
Output is correct |
37 |
Correct |
5 ms |
760 KB |
Output is correct |
38 |
Correct |
5 ms |
636 KB |
Output is correct |
39 |
Correct |
5 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
760 KB |
Output is correct |
41 |
Correct |
5 ms |
632 KB |
Output is correct |
42 |
Correct |
5 ms |
760 KB |
Output is correct |
43 |
Correct |
5 ms |
632 KB |
Output is correct |
44 |
Correct |
5 ms |
632 KB |
Output is correct |
45 |
Correct |
5 ms |
760 KB |
Output is correct |
46 |
Correct |
5 ms |
760 KB |
Output is correct |
47 |
Correct |
5 ms |
632 KB |
Output is correct |
48 |
Correct |
5 ms |
632 KB |
Output is correct |
49 |
Correct |
5 ms |
680 KB |
Output is correct |
50 |
Correct |
5 ms |
632 KB |
Output is correct |
51 |
Correct |
5 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
12 ms |
404 KB |
Output is correct |
9 |
Correct |
2 ms |
380 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 |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
636 KB |
Output is correct |
31 |
Correct |
5 ms |
632 KB |
Output is correct |
32 |
Correct |
5 ms |
632 KB |
Output is correct |
33 |
Correct |
5 ms |
632 KB |
Output is correct |
34 |
Correct |
5 ms |
632 KB |
Output is correct |
35 |
Correct |
5 ms |
760 KB |
Output is correct |
36 |
Correct |
6 ms |
632 KB |
Output is correct |
37 |
Correct |
5 ms |
760 KB |
Output is correct |
38 |
Correct |
5 ms |
636 KB |
Output is correct |
39 |
Correct |
5 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
760 KB |
Output is correct |
41 |
Correct |
5 ms |
632 KB |
Output is correct |
42 |
Correct |
5 ms |
760 KB |
Output is correct |
43 |
Correct |
5 ms |
632 KB |
Output is correct |
44 |
Correct |
5 ms |
632 KB |
Output is correct |
45 |
Correct |
5 ms |
760 KB |
Output is correct |
46 |
Correct |
5 ms |
760 KB |
Output is correct |
47 |
Correct |
5 ms |
632 KB |
Output is correct |
48 |
Correct |
5 ms |
632 KB |
Output is correct |
49 |
Correct |
5 ms |
680 KB |
Output is correct |
50 |
Correct |
5 ms |
632 KB |
Output is correct |
51 |
Correct |
5 ms |
632 KB |
Output is correct |
52 |
Correct |
383 ms |
24372 KB |
Output is correct |
53 |
Correct |
331 ms |
28936 KB |
Output is correct |
54 |
Correct |
335 ms |
29040 KB |
Output is correct |
55 |
Correct |
337 ms |
29128 KB |
Output is correct |
56 |
Correct |
326 ms |
29080 KB |
Output is correct |
57 |
Correct |
342 ms |
29000 KB |
Output is correct |
58 |
Correct |
341 ms |
29088 KB |
Output is correct |
59 |
Correct |
339 ms |
28976 KB |
Output is correct |
60 |
Correct |
334 ms |
29056 KB |
Output is correct |
61 |
Correct |
339 ms |
28916 KB |
Output is correct |
62 |
Correct |
343 ms |
29060 KB |
Output is correct |
63 |
Correct |
381 ms |
29016 KB |
Output is correct |
64 |
Correct |
346 ms |
29048 KB |
Output is correct |
65 |
Correct |
331 ms |
29180 KB |
Output is correct |
66 |
Correct |
328 ms |
29112 KB |
Output is correct |
67 |
Correct |
333 ms |
28964 KB |
Output is correct |
68 |
Correct |
329 ms |
29064 KB |
Output is correct |