#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
using namespace std;
#define int ll
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
const int N = 5e5 + 11;
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
int n;
pii a[N];
main() {
cin>>n;
fo(i,1,n,1) cin>>a[i].F>>a[i].S;
sort(a+1,a+n+1, greater<pii>());
int r = 0,sum=0,ans=-2e18+11;
fo(l,1,n,1) {
if (r<l) r=l,sum=a[l].S;
while (r + 1 <= n) {
chmax(ans,sum-a[l].F+a[r].F);
int val1=sum-a[l].F+a[r].F;
int val2=sum+a[r+1].S-a[l].F+a[r+1].F;
if (1) ++r,sum+=a[r].S;
else break;
}
chmax(ans,sum-a[l].F+a[r].F);
r=l;
}
cout<<ans;
return 0;
}
Compilation message
art.cpp:25:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
art.cpp: In function 'int main()':
art.cpp:34:11: warning: unused variable 'val1' [-Wunused-variable]
int val1=sum-a[l].F+a[r].F;
^~~~
art.cpp:35:11: warning: unused variable 'val2' [-Wunused-variable]
int val2=sum+a[r+1].S-a[l].F+a[r+1].F;
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
28 ms |
624 KB |
Output is correct |
28 |
Correct |
27 ms |
504 KB |
Output is correct |
29 |
Correct |
28 ms |
504 KB |
Output is correct |
30 |
Correct |
27 ms |
508 KB |
Output is correct |
31 |
Correct |
28 ms |
504 KB |
Output is correct |
32 |
Correct |
27 ms |
508 KB |
Output is correct |
33 |
Correct |
28 ms |
504 KB |
Output is correct |
34 |
Correct |
28 ms |
504 KB |
Output is correct |
35 |
Correct |
29 ms |
632 KB |
Output is correct |
36 |
Correct |
27 ms |
504 KB |
Output is correct |
37 |
Correct |
27 ms |
504 KB |
Output is correct |
38 |
Correct |
28 ms |
504 KB |
Output is correct |
39 |
Correct |
27 ms |
504 KB |
Output is correct |
40 |
Correct |
27 ms |
504 KB |
Output is correct |
41 |
Correct |
29 ms |
632 KB |
Output is correct |
42 |
Correct |
27 ms |
504 KB |
Output is correct |
43 |
Correct |
29 ms |
632 KB |
Output is correct |
44 |
Correct |
27 ms |
504 KB |
Output is correct |
45 |
Correct |
27 ms |
504 KB |
Output is correct |
46 |
Correct |
27 ms |
504 KB |
Output is correct |
47 |
Correct |
28 ms |
504 KB |
Output is correct |
48 |
Correct |
29 ms |
632 KB |
Output is correct |
49 |
Correct |
28 ms |
504 KB |
Output is correct |
50 |
Correct |
27 ms |
504 KB |
Output is correct |
51 |
Correct |
27 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
28 ms |
624 KB |
Output is correct |
28 |
Correct |
27 ms |
504 KB |
Output is correct |
29 |
Correct |
28 ms |
504 KB |
Output is correct |
30 |
Correct |
27 ms |
508 KB |
Output is correct |
31 |
Correct |
28 ms |
504 KB |
Output is correct |
32 |
Correct |
27 ms |
508 KB |
Output is correct |
33 |
Correct |
28 ms |
504 KB |
Output is correct |
34 |
Correct |
28 ms |
504 KB |
Output is correct |
35 |
Correct |
29 ms |
632 KB |
Output is correct |
36 |
Correct |
27 ms |
504 KB |
Output is correct |
37 |
Correct |
27 ms |
504 KB |
Output is correct |
38 |
Correct |
28 ms |
504 KB |
Output is correct |
39 |
Correct |
27 ms |
504 KB |
Output is correct |
40 |
Correct |
27 ms |
504 KB |
Output is correct |
41 |
Correct |
29 ms |
632 KB |
Output is correct |
42 |
Correct |
27 ms |
504 KB |
Output is correct |
43 |
Correct |
29 ms |
632 KB |
Output is correct |
44 |
Correct |
27 ms |
504 KB |
Output is correct |
45 |
Correct |
27 ms |
504 KB |
Output is correct |
46 |
Correct |
27 ms |
504 KB |
Output is correct |
47 |
Correct |
28 ms |
504 KB |
Output is correct |
48 |
Correct |
29 ms |
632 KB |
Output is correct |
49 |
Correct |
28 ms |
504 KB |
Output is correct |
50 |
Correct |
27 ms |
504 KB |
Output is correct |
51 |
Correct |
27 ms |
504 KB |
Output is correct |
52 |
Execution timed out |
1081 ms |
20728 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |