#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const int N = 5e5+5;
ll a[N],p[N];
int n;
set<ll>s;
struct art{
ll A,B;
bool operator < (const art &rhs) const{
return A<rhs.A;
}
}d[N];
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>d[i].A>>d[i].B;
sort(d+1,d+1+n);
s.insert(-d[1].A);
ll ans=-1;
for(int i=1;i<=n;i++){
ans=max(ans,d[i].B);
p[i]=p[i-1]+d[i].B;
}
for(int i=2;i<=n;i++){
ll val=*(s.begin());
ans=max(ans,p[i]-d[i].A-val);
s.insert(p[i-1]-d[i].A);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
3 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
676 KB |
Output is correct |
14 |
Correct |
2 ms |
684 KB |
Output is correct |
15 |
Correct |
2 ms |
708 KB |
Output is correct |
16 |
Correct |
2 ms |
716 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
3 ms |
748 KB |
Output is correct |
21 |
Correct |
2 ms |
756 KB |
Output is correct |
22 |
Correct |
2 ms |
764 KB |
Output is correct |
23 |
Correct |
1 ms |
772 KB |
Output is correct |
24 |
Correct |
2 ms |
772 KB |
Output is correct |
25 |
Correct |
2 ms |
788 KB |
Output is correct |
26 |
Correct |
2 ms |
820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
3 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
676 KB |
Output is correct |
14 |
Correct |
2 ms |
684 KB |
Output is correct |
15 |
Correct |
2 ms |
708 KB |
Output is correct |
16 |
Correct |
2 ms |
716 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
3 ms |
748 KB |
Output is correct |
21 |
Correct |
2 ms |
756 KB |
Output is correct |
22 |
Correct |
2 ms |
764 KB |
Output is correct |
23 |
Correct |
1 ms |
772 KB |
Output is correct |
24 |
Correct |
2 ms |
772 KB |
Output is correct |
25 |
Correct |
2 ms |
788 KB |
Output is correct |
26 |
Correct |
2 ms |
820 KB |
Output is correct |
27 |
Correct |
5 ms |
1188 KB |
Output is correct |
28 |
Correct |
5 ms |
1316 KB |
Output is correct |
29 |
Correct |
5 ms |
1444 KB |
Output is correct |
30 |
Correct |
5 ms |
1572 KB |
Output is correct |
31 |
Correct |
5 ms |
1700 KB |
Output is correct |
32 |
Correct |
7 ms |
1828 KB |
Output is correct |
33 |
Correct |
5 ms |
1956 KB |
Output is correct |
34 |
Correct |
5 ms |
2084 KB |
Output is correct |
35 |
Correct |
5 ms |
2224 KB |
Output is correct |
36 |
Correct |
6 ms |
2340 KB |
Output is correct |
37 |
Correct |
5 ms |
2468 KB |
Output is correct |
38 |
Correct |
5 ms |
2596 KB |
Output is correct |
39 |
Correct |
5 ms |
2724 KB |
Output is correct |
40 |
Correct |
5 ms |
2856 KB |
Output is correct |
41 |
Correct |
5 ms |
2980 KB |
Output is correct |
42 |
Correct |
6 ms |
3104 KB |
Output is correct |
43 |
Correct |
5 ms |
3232 KB |
Output is correct |
44 |
Correct |
6 ms |
3360 KB |
Output is correct |
45 |
Correct |
6 ms |
3488 KB |
Output is correct |
46 |
Correct |
6 ms |
3616 KB |
Output is correct |
47 |
Correct |
6 ms |
3744 KB |
Output is correct |
48 |
Correct |
5 ms |
3880 KB |
Output is correct |
49 |
Correct |
5 ms |
4000 KB |
Output is correct |
50 |
Correct |
6 ms |
4128 KB |
Output is correct |
51 |
Correct |
5 ms |
4256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
608 KB |
Output is correct |
4 |
Correct |
2 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
2 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
3 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
676 KB |
Output is correct |
14 |
Correct |
2 ms |
684 KB |
Output is correct |
15 |
Correct |
2 ms |
708 KB |
Output is correct |
16 |
Correct |
2 ms |
716 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
3 ms |
748 KB |
Output is correct |
21 |
Correct |
2 ms |
756 KB |
Output is correct |
22 |
Correct |
2 ms |
764 KB |
Output is correct |
23 |
Correct |
1 ms |
772 KB |
Output is correct |
24 |
Correct |
2 ms |
772 KB |
Output is correct |
25 |
Correct |
2 ms |
788 KB |
Output is correct |
26 |
Correct |
2 ms |
820 KB |
Output is correct |
27 |
Correct |
5 ms |
1188 KB |
Output is correct |
28 |
Correct |
5 ms |
1316 KB |
Output is correct |
29 |
Correct |
5 ms |
1444 KB |
Output is correct |
30 |
Correct |
5 ms |
1572 KB |
Output is correct |
31 |
Correct |
5 ms |
1700 KB |
Output is correct |
32 |
Correct |
7 ms |
1828 KB |
Output is correct |
33 |
Correct |
5 ms |
1956 KB |
Output is correct |
34 |
Correct |
5 ms |
2084 KB |
Output is correct |
35 |
Correct |
5 ms |
2224 KB |
Output is correct |
36 |
Correct |
6 ms |
2340 KB |
Output is correct |
37 |
Correct |
5 ms |
2468 KB |
Output is correct |
38 |
Correct |
5 ms |
2596 KB |
Output is correct |
39 |
Correct |
5 ms |
2724 KB |
Output is correct |
40 |
Correct |
5 ms |
2856 KB |
Output is correct |
41 |
Correct |
5 ms |
2980 KB |
Output is correct |
42 |
Correct |
6 ms |
3104 KB |
Output is correct |
43 |
Correct |
5 ms |
3232 KB |
Output is correct |
44 |
Correct |
6 ms |
3360 KB |
Output is correct |
45 |
Correct |
6 ms |
3488 KB |
Output is correct |
46 |
Correct |
6 ms |
3616 KB |
Output is correct |
47 |
Correct |
6 ms |
3744 KB |
Output is correct |
48 |
Correct |
5 ms |
3880 KB |
Output is correct |
49 |
Correct |
5 ms |
4000 KB |
Output is correct |
50 |
Correct |
6 ms |
4128 KB |
Output is correct |
51 |
Correct |
5 ms |
4256 KB |
Output is correct |
52 |
Correct |
345 ms |
51732 KB |
Output is correct |
53 |
Correct |
355 ms |
64572 KB |
Output is correct |
54 |
Correct |
365 ms |
75308 KB |
Output is correct |
55 |
Correct |
375 ms |
75364 KB |
Output is correct |
56 |
Correct |
430 ms |
75468 KB |
Output is correct |
57 |
Correct |
443 ms |
75480 KB |
Output is correct |
58 |
Correct |
397 ms |
83548 KB |
Output is correct |
59 |
Correct |
432 ms |
93860 KB |
Output is correct |
60 |
Correct |
366 ms |
93860 KB |
Output is correct |
61 |
Correct |
371 ms |
93908 KB |
Output is correct |
62 |
Correct |
368 ms |
93908 KB |
Output is correct |
63 |
Correct |
360 ms |
93908 KB |
Output is correct |
64 |
Correct |
354 ms |
93924 KB |
Output is correct |
65 |
Correct |
345 ms |
93924 KB |
Output is correct |
66 |
Correct |
349 ms |
93924 KB |
Output is correct |
67 |
Correct |
359 ms |
93924 KB |
Output is correct |
68 |
Correct |
448 ms |
93924 KB |
Output is correct |