#include <iostream>
#include <algorithm>
using namespace std;
long long* X;
long long* Y;
bool f(long long a, long long b)
{
return X[a] < X[b];
}
int main()
{
long long N;
cin >> N;
X = new long long[N+1];
Y = new long long[N+1];
long long A[N+1], B[N+1];
for(long long i = 1; i <= N; i++) cin >> X[i] >> Y[i];
long long I[N+1];
for(long long i = 0; i <= N; i++) I[i] = i;
sort(I+1, I+N+1, f);
long long a = 1;
for(long long i:I)
{
if(i == 0) continue;
A[a] = X[i];
B[a] = Y[i];
a++;
}
for(long long i = 2; i <= N; i++) B[i] += B[i-1];
A[0] = B[0] = 0;
for(long long i = 1; i <= N; i++)
{
X[i] = A[i] - B[i-1];
Y[i] = B[i] - A[i];
}
for(long long i = N-1; i >= 1; i--) Y[i] = max(Y[i], Y[i+1]);
long long res = 0;
for(long long i = 1; i <= N; i++) res = max(res, X[i] + Y[i]);
cout << res << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
368 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
248 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 |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
6 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
368 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
248 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 |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
6 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
380 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 |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 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 |
6 ms |
368 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
248 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 |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
6 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
380 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 |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 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 |
13 ms |
632 KB |
Output is correct |
28 |
Correct |
14 ms |
568 KB |
Output is correct |
29 |
Correct |
13 ms |
636 KB |
Output is correct |
30 |
Correct |
14 ms |
632 KB |
Output is correct |
31 |
Correct |
13 ms |
628 KB |
Output is correct |
32 |
Correct |
13 ms |
632 KB |
Output is correct |
33 |
Correct |
14 ms |
636 KB |
Output is correct |
34 |
Correct |
13 ms |
632 KB |
Output is correct |
35 |
Correct |
13 ms |
632 KB |
Output is correct |
36 |
Correct |
14 ms |
632 KB |
Output is correct |
37 |
Correct |
13 ms |
632 KB |
Output is correct |
38 |
Correct |
14 ms |
632 KB |
Output is correct |
39 |
Correct |
13 ms |
632 KB |
Output is correct |
40 |
Correct |
13 ms |
632 KB |
Output is correct |
41 |
Correct |
13 ms |
632 KB |
Output is correct |
42 |
Correct |
13 ms |
632 KB |
Output is correct |
43 |
Correct |
13 ms |
632 KB |
Output is correct |
44 |
Correct |
13 ms |
632 KB |
Output is correct |
45 |
Correct |
16 ms |
632 KB |
Output is correct |
46 |
Correct |
13 ms |
632 KB |
Output is correct |
47 |
Correct |
14 ms |
632 KB |
Output is correct |
48 |
Correct |
13 ms |
636 KB |
Output is correct |
49 |
Correct |
13 ms |
632 KB |
Output is correct |
50 |
Correct |
17 ms |
632 KB |
Output is correct |
51 |
Correct |
13 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
368 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
248 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 |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
6 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
380 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 |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 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 |
13 ms |
632 KB |
Output is correct |
28 |
Correct |
14 ms |
568 KB |
Output is correct |
29 |
Correct |
13 ms |
636 KB |
Output is correct |
30 |
Correct |
14 ms |
632 KB |
Output is correct |
31 |
Correct |
13 ms |
628 KB |
Output is correct |
32 |
Correct |
13 ms |
632 KB |
Output is correct |
33 |
Correct |
14 ms |
636 KB |
Output is correct |
34 |
Correct |
13 ms |
632 KB |
Output is correct |
35 |
Correct |
13 ms |
632 KB |
Output is correct |
36 |
Correct |
14 ms |
632 KB |
Output is correct |
37 |
Correct |
13 ms |
632 KB |
Output is correct |
38 |
Correct |
14 ms |
632 KB |
Output is correct |
39 |
Correct |
13 ms |
632 KB |
Output is correct |
40 |
Correct |
13 ms |
632 KB |
Output is correct |
41 |
Correct |
13 ms |
632 KB |
Output is correct |
42 |
Correct |
13 ms |
632 KB |
Output is correct |
43 |
Correct |
13 ms |
632 KB |
Output is correct |
44 |
Correct |
13 ms |
632 KB |
Output is correct |
45 |
Correct |
16 ms |
632 KB |
Output is correct |
46 |
Correct |
13 ms |
632 KB |
Output is correct |
47 |
Correct |
14 ms |
632 KB |
Output is correct |
48 |
Correct |
13 ms |
636 KB |
Output is correct |
49 |
Correct |
13 ms |
632 KB |
Output is correct |
50 |
Correct |
17 ms |
632 KB |
Output is correct |
51 |
Correct |
13 ms |
632 KB |
Output is correct |
52 |
Correct |
897 ms |
32504 KB |
Output is correct |
53 |
Correct |
865 ms |
32504 KB |
Output is correct |
54 |
Correct |
867 ms |
32504 KB |
Output is correct |
55 |
Correct |
873 ms |
32632 KB |
Output is correct |
56 |
Correct |
871 ms |
32632 KB |
Output is correct |
57 |
Correct |
864 ms |
32628 KB |
Output is correct |
58 |
Correct |
867 ms |
32632 KB |
Output is correct |
59 |
Correct |
893 ms |
32760 KB |
Output is correct |
60 |
Correct |
896 ms |
32568 KB |
Output is correct |
61 |
Correct |
867 ms |
32504 KB |
Output is correct |
62 |
Correct |
898 ms |
32692 KB |
Output is correct |
63 |
Correct |
917 ms |
32704 KB |
Output is correct |
64 |
Correct |
906 ms |
32688 KB |
Output is correct |
65 |
Correct |
916 ms |
32632 KB |
Output is correct |
66 |
Correct |
894 ms |
32544 KB |
Output is correct |
67 |
Correct |
890 ms |
32576 KB |
Output is correct |
68 |
Correct |
890 ms |
32504 KB |
Output is correct |