#include <bits/stdc++.h>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define int ll
#define double ld
const int MOD = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-9;
int N, P[500001], DP[500001];
pair<int, int> A[500001];
int solve(int i) {
if(i == N + 1)
return -A[N].ff;
if(DP[i] != -1) return DP[i];
int best = A[i].ss + max(solve(i + 1), -A[i].ff);
return DP[i] = best;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N; memset(DP, -1, sizeof DP);
for(int l = 1; l <= N; l++)
cin >> A[l].ff >> A[l].ss;
sort(A + 1, A + N + 1);
int res = 0;
for(int l = 1; l <= N; l++)
res = max(res, A[l].ff + solve(l));
cout << res << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4168 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4152 KB |
Output is correct |
6 |
Correct |
2 ms |
4168 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4168 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4152 KB |
Output is correct |
6 |
Correct |
2 ms |
4168 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
3 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
2 ms |
4176 KB |
Output is correct |
15 |
Correct |
3 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
4172 KB |
Output is correct |
17 |
Correct |
2 ms |
4176 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
3 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4176 KB |
Output is correct |
24 |
Correct |
2 ms |
4180 KB |
Output is correct |
25 |
Correct |
2 ms |
4180 KB |
Output is correct |
26 |
Correct |
3 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4168 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4152 KB |
Output is correct |
6 |
Correct |
2 ms |
4168 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
3 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
2 ms |
4176 KB |
Output is correct |
15 |
Correct |
3 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
4172 KB |
Output is correct |
17 |
Correct |
2 ms |
4176 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
3 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4176 KB |
Output is correct |
24 |
Correct |
2 ms |
4180 KB |
Output is correct |
25 |
Correct |
2 ms |
4180 KB |
Output is correct |
26 |
Correct |
3 ms |
4176 KB |
Output is correct |
27 |
Correct |
4 ms |
4564 KB |
Output is correct |
28 |
Correct |
4 ms |
4564 KB |
Output is correct |
29 |
Correct |
4 ms |
4568 KB |
Output is correct |
30 |
Correct |
4 ms |
4564 KB |
Output is correct |
31 |
Correct |
4 ms |
4564 KB |
Output is correct |
32 |
Correct |
4 ms |
4564 KB |
Output is correct |
33 |
Correct |
4 ms |
4564 KB |
Output is correct |
34 |
Correct |
3 ms |
4568 KB |
Output is correct |
35 |
Correct |
4 ms |
4564 KB |
Output is correct |
36 |
Correct |
4 ms |
4564 KB |
Output is correct |
37 |
Correct |
4 ms |
4564 KB |
Output is correct |
38 |
Correct |
4 ms |
4568 KB |
Output is correct |
39 |
Correct |
4 ms |
4564 KB |
Output is correct |
40 |
Correct |
4 ms |
4620 KB |
Output is correct |
41 |
Correct |
4 ms |
4564 KB |
Output is correct |
42 |
Correct |
4 ms |
4696 KB |
Output is correct |
43 |
Correct |
4 ms |
4564 KB |
Output is correct |
44 |
Correct |
4 ms |
4628 KB |
Output is correct |
45 |
Correct |
4 ms |
4564 KB |
Output is correct |
46 |
Correct |
4 ms |
4564 KB |
Output is correct |
47 |
Correct |
4 ms |
4564 KB |
Output is correct |
48 |
Correct |
4 ms |
4660 KB |
Output is correct |
49 |
Correct |
4 ms |
4564 KB |
Output is correct |
50 |
Correct |
4 ms |
4692 KB |
Output is correct |
51 |
Correct |
4 ms |
4660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4168 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4152 KB |
Output is correct |
6 |
Correct |
2 ms |
4168 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
3 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
2 ms |
4176 KB |
Output is correct |
15 |
Correct |
3 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
4172 KB |
Output is correct |
17 |
Correct |
2 ms |
4176 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
3 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4176 KB |
Output is correct |
24 |
Correct |
2 ms |
4180 KB |
Output is correct |
25 |
Correct |
2 ms |
4180 KB |
Output is correct |
26 |
Correct |
3 ms |
4176 KB |
Output is correct |
27 |
Correct |
4 ms |
4564 KB |
Output is correct |
28 |
Correct |
4 ms |
4564 KB |
Output is correct |
29 |
Correct |
4 ms |
4568 KB |
Output is correct |
30 |
Correct |
4 ms |
4564 KB |
Output is correct |
31 |
Correct |
4 ms |
4564 KB |
Output is correct |
32 |
Correct |
4 ms |
4564 KB |
Output is correct |
33 |
Correct |
4 ms |
4564 KB |
Output is correct |
34 |
Correct |
3 ms |
4568 KB |
Output is correct |
35 |
Correct |
4 ms |
4564 KB |
Output is correct |
36 |
Correct |
4 ms |
4564 KB |
Output is correct |
37 |
Correct |
4 ms |
4564 KB |
Output is correct |
38 |
Correct |
4 ms |
4568 KB |
Output is correct |
39 |
Correct |
4 ms |
4564 KB |
Output is correct |
40 |
Correct |
4 ms |
4620 KB |
Output is correct |
41 |
Correct |
4 ms |
4564 KB |
Output is correct |
42 |
Correct |
4 ms |
4696 KB |
Output is correct |
43 |
Correct |
4 ms |
4564 KB |
Output is correct |
44 |
Correct |
4 ms |
4628 KB |
Output is correct |
45 |
Correct |
4 ms |
4564 KB |
Output is correct |
46 |
Correct |
4 ms |
4564 KB |
Output is correct |
47 |
Correct |
4 ms |
4564 KB |
Output is correct |
48 |
Correct |
4 ms |
4660 KB |
Output is correct |
49 |
Correct |
4 ms |
4564 KB |
Output is correct |
50 |
Correct |
4 ms |
4692 KB |
Output is correct |
51 |
Correct |
4 ms |
4660 KB |
Output is correct |
52 |
Correct |
203 ms |
47528 KB |
Output is correct |
53 |
Correct |
200 ms |
48232 KB |
Output is correct |
54 |
Correct |
187 ms |
48156 KB |
Output is correct |
55 |
Correct |
216 ms |
48076 KB |
Output is correct |
56 |
Correct |
184 ms |
48264 KB |
Output is correct |
57 |
Correct |
199 ms |
48124 KB |
Output is correct |
58 |
Correct |
196 ms |
48064 KB |
Output is correct |
59 |
Correct |
207 ms |
48416 KB |
Output is correct |
60 |
Correct |
183 ms |
48104 KB |
Output is correct |
61 |
Correct |
183 ms |
48028 KB |
Output is correct |
62 |
Correct |
187 ms |
48184 KB |
Output is correct |
63 |
Correct |
201 ms |
48208 KB |
Output is correct |
64 |
Correct |
191 ms |
48180 KB |
Output is correct |
65 |
Correct |
196 ms |
48200 KB |
Output is correct |
66 |
Correct |
187 ms |
48180 KB |
Output is correct |
67 |
Correct |
196 ms |
48168 KB |
Output is correct |
68 |
Correct |
205 ms |
48168 KB |
Output is correct |