#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N=5e5+5;
int const mod=1e9+7;
pair<ll,ll> arr[N];
ll largest_subarray_sum(vector<ll> v, int n){
ll ans=0;
ll cur=0;
for(int i=0;i<n;i++){
if(cur+v[i]>=0)
cur+=v[i];
else
cur=0;
ans=max(ans,cur);
}
return ans;
}
void solve(){
int n;
cin>>n;
for (int i = 0; i < n; ++i)
cin>>arr[i].first>>arr[i].second;
sort(arr,arr+n);
vector<ll> v;
for(int i=0;i<n-1;i++){
v.push_back(arr[i].second);
v.push_back(arr[i].first-arr[i+1].first);
}
v.push_back(arr[n-1].second);
cout<<largest_subarray_sum(v,2*n-1)<<endl;
}
int main(){
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
448 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
448 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
4 ms |
860 KB |
Output is correct |
28 |
Correct |
4 ms |
708 KB |
Output is correct |
29 |
Correct |
4 ms |
860 KB |
Output is correct |
30 |
Correct |
4 ms |
860 KB |
Output is correct |
31 |
Correct |
4 ms |
860 KB |
Output is correct |
32 |
Correct |
4 ms |
860 KB |
Output is correct |
33 |
Correct |
5 ms |
816 KB |
Output is correct |
34 |
Correct |
4 ms |
812 KB |
Output is correct |
35 |
Correct |
4 ms |
856 KB |
Output is correct |
36 |
Correct |
4 ms |
860 KB |
Output is correct |
37 |
Correct |
6 ms |
632 KB |
Output is correct |
38 |
Correct |
4 ms |
808 KB |
Output is correct |
39 |
Correct |
4 ms |
860 KB |
Output is correct |
40 |
Correct |
7 ms |
860 KB |
Output is correct |
41 |
Correct |
4 ms |
860 KB |
Output is correct |
42 |
Correct |
5 ms |
860 KB |
Output is correct |
43 |
Correct |
4 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
860 KB |
Output is correct |
45 |
Correct |
4 ms |
860 KB |
Output is correct |
46 |
Correct |
4 ms |
860 KB |
Output is correct |
47 |
Correct |
6 ms |
860 KB |
Output is correct |
48 |
Correct |
4 ms |
860 KB |
Output is correct |
49 |
Correct |
4 ms |
860 KB |
Output is correct |
50 |
Correct |
4 ms |
816 KB |
Output is correct |
51 |
Correct |
4 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
448 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
4 ms |
860 KB |
Output is correct |
28 |
Correct |
4 ms |
708 KB |
Output is correct |
29 |
Correct |
4 ms |
860 KB |
Output is correct |
30 |
Correct |
4 ms |
860 KB |
Output is correct |
31 |
Correct |
4 ms |
860 KB |
Output is correct |
32 |
Correct |
4 ms |
860 KB |
Output is correct |
33 |
Correct |
5 ms |
816 KB |
Output is correct |
34 |
Correct |
4 ms |
812 KB |
Output is correct |
35 |
Correct |
4 ms |
856 KB |
Output is correct |
36 |
Correct |
4 ms |
860 KB |
Output is correct |
37 |
Correct |
6 ms |
632 KB |
Output is correct |
38 |
Correct |
4 ms |
808 KB |
Output is correct |
39 |
Correct |
4 ms |
860 KB |
Output is correct |
40 |
Correct |
7 ms |
860 KB |
Output is correct |
41 |
Correct |
4 ms |
860 KB |
Output is correct |
42 |
Correct |
5 ms |
860 KB |
Output is correct |
43 |
Correct |
4 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
860 KB |
Output is correct |
45 |
Correct |
4 ms |
860 KB |
Output is correct |
46 |
Correct |
4 ms |
860 KB |
Output is correct |
47 |
Correct |
6 ms |
860 KB |
Output is correct |
48 |
Correct |
4 ms |
860 KB |
Output is correct |
49 |
Correct |
4 ms |
860 KB |
Output is correct |
50 |
Correct |
4 ms |
816 KB |
Output is correct |
51 |
Correct |
4 ms |
860 KB |
Output is correct |
52 |
Correct |
412 ms |
36428 KB |
Output is correct |
53 |
Correct |
407 ms |
36532 KB |
Output is correct |
54 |
Correct |
395 ms |
36488 KB |
Output is correct |
55 |
Correct |
394 ms |
36556 KB |
Output is correct |
56 |
Correct |
405 ms |
36628 KB |
Output is correct |
57 |
Correct |
387 ms |
36548 KB |
Output is correct |
58 |
Correct |
376 ms |
36496 KB |
Output is correct |
59 |
Correct |
388 ms |
36668 KB |
Output is correct |
60 |
Correct |
396 ms |
36668 KB |
Output is correct |
61 |
Correct |
388 ms |
36400 KB |
Output is correct |
62 |
Correct |
396 ms |
36888 KB |
Output is correct |
63 |
Correct |
394 ms |
36536 KB |
Output is correct |
64 |
Correct |
419 ms |
36784 KB |
Output is correct |
65 |
Correct |
381 ms |
36560 KB |
Output is correct |
66 |
Correct |
391 ms |
36928 KB |
Output is correct |
67 |
Correct |
386 ms |
36576 KB |
Output is correct |
68 |
Correct |
399 ms |
36664 KB |
Output is correct |