#include<bits/stdc++.h>
using namespace std;
long long psm[500005];
int main(){
int n;
cin>>n;
vector<pair<long long,long long> >v;
long long mx2=-1*LLONG_MAX,mx=-1*LLONG_MAX;
for(int i=0;i<n;i++){
long long a,b;
cin>>a>>b;
v.push_back({a,b});
}
sort(v.begin(),v.end());
long long sum=0;
for(int i=0;i<n;i++){
sum+=v[i].second;
psm[i+1]=sum;
}
//cout<<endl;
for(int i=0;i<n;i++){
if(v[i].first-psm[i]>mx2){
mx2=v[i].first-psm[i];
}
//cout<<i<<" "<<psm[i+1]<<" "<<v[i].first<<" "<<mx2<<" ";
if(psm[i+1]-v[i].first+mx2>mx){
mx=psm[i+1]-v[i].first+mx2;
}
//cout<<mx<<"\n";
}
cout<<mx;
//3 1 1 20 2 21 30
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
6 ms |
676 KB |
Output is correct |
28 |
Correct |
6 ms |
684 KB |
Output is correct |
29 |
Correct |
5 ms |
596 KB |
Output is correct |
30 |
Correct |
6 ms |
596 KB |
Output is correct |
31 |
Correct |
7 ms |
668 KB |
Output is correct |
32 |
Correct |
7 ms |
580 KB |
Output is correct |
33 |
Correct |
6 ms |
596 KB |
Output is correct |
34 |
Correct |
6 ms |
596 KB |
Output is correct |
35 |
Correct |
6 ms |
596 KB |
Output is correct |
36 |
Correct |
6 ms |
596 KB |
Output is correct |
37 |
Correct |
5 ms |
684 KB |
Output is correct |
38 |
Correct |
6 ms |
596 KB |
Output is correct |
39 |
Correct |
6 ms |
648 KB |
Output is correct |
40 |
Correct |
6 ms |
596 KB |
Output is correct |
41 |
Correct |
6 ms |
572 KB |
Output is correct |
42 |
Correct |
6 ms |
616 KB |
Output is correct |
43 |
Correct |
6 ms |
576 KB |
Output is correct |
44 |
Correct |
6 ms |
596 KB |
Output is correct |
45 |
Correct |
6 ms |
576 KB |
Output is correct |
46 |
Correct |
6 ms |
596 KB |
Output is correct |
47 |
Correct |
6 ms |
576 KB |
Output is correct |
48 |
Correct |
5 ms |
596 KB |
Output is correct |
49 |
Correct |
6 ms |
576 KB |
Output is correct |
50 |
Correct |
6 ms |
596 KB |
Output is correct |
51 |
Correct |
7 ms |
644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
6 ms |
676 KB |
Output is correct |
28 |
Correct |
6 ms |
684 KB |
Output is correct |
29 |
Correct |
5 ms |
596 KB |
Output is correct |
30 |
Correct |
6 ms |
596 KB |
Output is correct |
31 |
Correct |
7 ms |
668 KB |
Output is correct |
32 |
Correct |
7 ms |
580 KB |
Output is correct |
33 |
Correct |
6 ms |
596 KB |
Output is correct |
34 |
Correct |
6 ms |
596 KB |
Output is correct |
35 |
Correct |
6 ms |
596 KB |
Output is correct |
36 |
Correct |
6 ms |
596 KB |
Output is correct |
37 |
Correct |
5 ms |
684 KB |
Output is correct |
38 |
Correct |
6 ms |
596 KB |
Output is correct |
39 |
Correct |
6 ms |
648 KB |
Output is correct |
40 |
Correct |
6 ms |
596 KB |
Output is correct |
41 |
Correct |
6 ms |
572 KB |
Output is correct |
42 |
Correct |
6 ms |
616 KB |
Output is correct |
43 |
Correct |
6 ms |
576 KB |
Output is correct |
44 |
Correct |
6 ms |
596 KB |
Output is correct |
45 |
Correct |
6 ms |
576 KB |
Output is correct |
46 |
Correct |
6 ms |
596 KB |
Output is correct |
47 |
Correct |
6 ms |
576 KB |
Output is correct |
48 |
Correct |
5 ms |
596 KB |
Output is correct |
49 |
Correct |
6 ms |
576 KB |
Output is correct |
50 |
Correct |
6 ms |
596 KB |
Output is correct |
51 |
Correct |
7 ms |
644 KB |
Output is correct |
52 |
Correct |
496 ms |
13116 KB |
Output is correct |
53 |
Correct |
504 ms |
13972 KB |
Output is correct |
54 |
Correct |
504 ms |
14040 KB |
Output is correct |
55 |
Correct |
496 ms |
13836 KB |
Output is correct |
56 |
Correct |
500 ms |
14020 KB |
Output is correct |
57 |
Correct |
502 ms |
13916 KB |
Output is correct |
58 |
Correct |
498 ms |
13964 KB |
Output is correct |
59 |
Correct |
506 ms |
14024 KB |
Output is correct |
60 |
Correct |
486 ms |
13920 KB |
Output is correct |
61 |
Correct |
508 ms |
13944 KB |
Output is correct |
62 |
Correct |
494 ms |
13892 KB |
Output is correct |
63 |
Correct |
520 ms |
13832 KB |
Output is correct |
64 |
Correct |
490 ms |
13888 KB |
Output is correct |
65 |
Correct |
495 ms |
13836 KB |
Output is correct |
66 |
Correct |
495 ms |
13964 KB |
Output is correct |
67 |
Correct |
489 ms |
14032 KB |
Output is correct |
68 |
Correct |
504 ms |
13936 KB |
Output is correct |