#include <bits/stdc++.h>
using namespace std;
struct pos
{
long long s, val;
bool operator<(pos b) const
{
return s < b.s;
}
};
long long n,ans;
pos v[500005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i].s>>v[i].val;
sort(v+1, v+n+1);
multiset<long long> s;
long long sum=0;
for(int i=1;i<=n;i++)
{
sum += v[i-1].val;
s.insert(sum - v[i].s);
ans = max(ans, sum+v[i].val - v[i].s - *s.begin());
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
264 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
264 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
268 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
264 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
268 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
0 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
720 KB |
Output is correct |
28 |
Correct |
2 ms |
720 KB |
Output is correct |
29 |
Correct |
2 ms |
720 KB |
Output is correct |
30 |
Correct |
3 ms |
720 KB |
Output is correct |
31 |
Correct |
2 ms |
720 KB |
Output is correct |
32 |
Correct |
3 ms |
720 KB |
Output is correct |
33 |
Correct |
3 ms |
720 KB |
Output is correct |
34 |
Correct |
3 ms |
720 KB |
Output is correct |
35 |
Correct |
3 ms |
720 KB |
Output is correct |
36 |
Correct |
2 ms |
724 KB |
Output is correct |
37 |
Correct |
3 ms |
720 KB |
Output is correct |
38 |
Correct |
2 ms |
720 KB |
Output is correct |
39 |
Correct |
3 ms |
720 KB |
Output is correct |
40 |
Correct |
3 ms |
720 KB |
Output is correct |
41 |
Correct |
2 ms |
720 KB |
Output is correct |
42 |
Correct |
3 ms |
720 KB |
Output is correct |
43 |
Correct |
3 ms |
720 KB |
Output is correct |
44 |
Correct |
2 ms |
720 KB |
Output is correct |
45 |
Correct |
3 ms |
728 KB |
Output is correct |
46 |
Correct |
3 ms |
720 KB |
Output is correct |
47 |
Correct |
4 ms |
716 KB |
Output is correct |
48 |
Correct |
2 ms |
720 KB |
Output is correct |
49 |
Correct |
2 ms |
720 KB |
Output is correct |
50 |
Correct |
3 ms |
720 KB |
Output is correct |
51 |
Correct |
2 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
264 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
268 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
0 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
720 KB |
Output is correct |
28 |
Correct |
2 ms |
720 KB |
Output is correct |
29 |
Correct |
2 ms |
720 KB |
Output is correct |
30 |
Correct |
3 ms |
720 KB |
Output is correct |
31 |
Correct |
2 ms |
720 KB |
Output is correct |
32 |
Correct |
3 ms |
720 KB |
Output is correct |
33 |
Correct |
3 ms |
720 KB |
Output is correct |
34 |
Correct |
3 ms |
720 KB |
Output is correct |
35 |
Correct |
3 ms |
720 KB |
Output is correct |
36 |
Correct |
2 ms |
724 KB |
Output is correct |
37 |
Correct |
3 ms |
720 KB |
Output is correct |
38 |
Correct |
2 ms |
720 KB |
Output is correct |
39 |
Correct |
3 ms |
720 KB |
Output is correct |
40 |
Correct |
3 ms |
720 KB |
Output is correct |
41 |
Correct |
2 ms |
720 KB |
Output is correct |
42 |
Correct |
3 ms |
720 KB |
Output is correct |
43 |
Correct |
3 ms |
720 KB |
Output is correct |
44 |
Correct |
2 ms |
720 KB |
Output is correct |
45 |
Correct |
3 ms |
728 KB |
Output is correct |
46 |
Correct |
3 ms |
720 KB |
Output is correct |
47 |
Correct |
4 ms |
716 KB |
Output is correct |
48 |
Correct |
2 ms |
720 KB |
Output is correct |
49 |
Correct |
2 ms |
720 KB |
Output is correct |
50 |
Correct |
3 ms |
720 KB |
Output is correct |
51 |
Correct |
2 ms |
720 KB |
Output is correct |
52 |
Correct |
228 ms |
44168 KB |
Output is correct |
53 |
Correct |
244 ms |
44224 KB |
Output is correct |
54 |
Correct |
229 ms |
44168 KB |
Output is correct |
55 |
Correct |
237 ms |
44184 KB |
Output is correct |
56 |
Correct |
252 ms |
44216 KB |
Output is correct |
57 |
Correct |
249 ms |
44220 KB |
Output is correct |
58 |
Correct |
235 ms |
44324 KB |
Output is correct |
59 |
Correct |
232 ms |
44248 KB |
Output is correct |
60 |
Correct |
243 ms |
44156 KB |
Output is correct |
61 |
Correct |
230 ms |
44096 KB |
Output is correct |
62 |
Correct |
226 ms |
44140 KB |
Output is correct |
63 |
Correct |
231 ms |
44172 KB |
Output is correct |
64 |
Correct |
236 ms |
44260 KB |
Output is correct |
65 |
Correct |
229 ms |
44184 KB |
Output is correct |
66 |
Correct |
228 ms |
44228 KB |
Output is correct |
67 |
Correct |
269 ms |
44172 KB |
Output is correct |
68 |
Correct |
283 ms |
44244 KB |
Output is correct |