#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ull unsigned long long
#define fi first
#define se second
#define ld long double
ll n, dp[5005][5005], pref[5005];
pair<ll, ll>arr[5005];
ll solve(ll l, ll r){
if(l > r) return 0;
if(dp[l][r]!=-1) return dp[l][r];
ll sums=(pref[r]-pref[l-1])-(arr[r].fi-arr[l].fi);
ll ans=sums;
ans=max(ans, solve(l+1, r));
ans=max(ans, solve(l, r-1));
return dp[l][r]=ans;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
memset(dp, -1, sizeof dp);
for(int i=1;i<=n;++i){
cin >> arr[i].fi >> arr[i].se;
}
sort(arr+1, arr+1+n);
for(int i=1;i<=n;++i) pref[i]=pref[i-1]+arr[i].se;
cout << solve(1, n) << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
196400 KB |
Output is correct |
2 |
Correct |
95 ms |
196320 KB |
Output is correct |
3 |
Correct |
90 ms |
196356 KB |
Output is correct |
4 |
Correct |
89 ms |
196292 KB |
Output is correct |
5 |
Correct |
91 ms |
196388 KB |
Output is correct |
6 |
Correct |
91 ms |
196276 KB |
Output is correct |
7 |
Correct |
96 ms |
196292 KB |
Output is correct |
8 |
Correct |
89 ms |
196384 KB |
Output is correct |
9 |
Correct |
89 ms |
196424 KB |
Output is correct |
10 |
Correct |
91 ms |
196328 KB |
Output is correct |
11 |
Correct |
88 ms |
196288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
196400 KB |
Output is correct |
2 |
Correct |
95 ms |
196320 KB |
Output is correct |
3 |
Correct |
90 ms |
196356 KB |
Output is correct |
4 |
Correct |
89 ms |
196292 KB |
Output is correct |
5 |
Correct |
91 ms |
196388 KB |
Output is correct |
6 |
Correct |
91 ms |
196276 KB |
Output is correct |
7 |
Correct |
96 ms |
196292 KB |
Output is correct |
8 |
Correct |
89 ms |
196384 KB |
Output is correct |
9 |
Correct |
89 ms |
196424 KB |
Output is correct |
10 |
Correct |
91 ms |
196328 KB |
Output is correct |
11 |
Correct |
88 ms |
196288 KB |
Output is correct |
12 |
Correct |
88 ms |
196292 KB |
Output is correct |
13 |
Correct |
89 ms |
196384 KB |
Output is correct |
14 |
Correct |
92 ms |
196384 KB |
Output is correct |
15 |
Correct |
87 ms |
196356 KB |
Output is correct |
16 |
Correct |
90 ms |
196420 KB |
Output is correct |
17 |
Correct |
89 ms |
196400 KB |
Output is correct |
18 |
Correct |
89 ms |
196320 KB |
Output is correct |
19 |
Correct |
88 ms |
196420 KB |
Output is correct |
20 |
Correct |
88 ms |
196332 KB |
Output is correct |
21 |
Correct |
98 ms |
196324 KB |
Output is correct |
22 |
Correct |
103 ms |
196292 KB |
Output is correct |
23 |
Correct |
99 ms |
196404 KB |
Output is correct |
24 |
Correct |
89 ms |
196428 KB |
Output is correct |
25 |
Correct |
89 ms |
196328 KB |
Output is correct |
26 |
Correct |
89 ms |
196404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
196400 KB |
Output is correct |
2 |
Correct |
95 ms |
196320 KB |
Output is correct |
3 |
Correct |
90 ms |
196356 KB |
Output is correct |
4 |
Correct |
89 ms |
196292 KB |
Output is correct |
5 |
Correct |
91 ms |
196388 KB |
Output is correct |
6 |
Correct |
91 ms |
196276 KB |
Output is correct |
7 |
Correct |
96 ms |
196292 KB |
Output is correct |
8 |
Correct |
89 ms |
196384 KB |
Output is correct |
9 |
Correct |
89 ms |
196424 KB |
Output is correct |
10 |
Correct |
91 ms |
196328 KB |
Output is correct |
11 |
Correct |
88 ms |
196288 KB |
Output is correct |
12 |
Correct |
88 ms |
196292 KB |
Output is correct |
13 |
Correct |
89 ms |
196384 KB |
Output is correct |
14 |
Correct |
92 ms |
196384 KB |
Output is correct |
15 |
Correct |
87 ms |
196356 KB |
Output is correct |
16 |
Correct |
90 ms |
196420 KB |
Output is correct |
17 |
Correct |
89 ms |
196400 KB |
Output is correct |
18 |
Correct |
89 ms |
196320 KB |
Output is correct |
19 |
Correct |
88 ms |
196420 KB |
Output is correct |
20 |
Correct |
88 ms |
196332 KB |
Output is correct |
21 |
Correct |
98 ms |
196324 KB |
Output is correct |
22 |
Correct |
103 ms |
196292 KB |
Output is correct |
23 |
Correct |
99 ms |
196404 KB |
Output is correct |
24 |
Correct |
89 ms |
196428 KB |
Output is correct |
25 |
Correct |
89 ms |
196328 KB |
Output is correct |
26 |
Correct |
89 ms |
196404 KB |
Output is correct |
27 |
Correct |
204 ms |
196804 KB |
Output is correct |
28 |
Correct |
200 ms |
196860 KB |
Output is correct |
29 |
Correct |
204 ms |
196852 KB |
Output is correct |
30 |
Correct |
203 ms |
196860 KB |
Output is correct |
31 |
Correct |
199 ms |
196804 KB |
Output is correct |
32 |
Correct |
210 ms |
196856 KB |
Output is correct |
33 |
Correct |
206 ms |
196804 KB |
Output is correct |
34 |
Correct |
206 ms |
196904 KB |
Output is correct |
35 |
Correct |
210 ms |
196932 KB |
Output is correct |
36 |
Correct |
201 ms |
196908 KB |
Output is correct |
37 |
Correct |
212 ms |
196856 KB |
Output is correct |
38 |
Correct |
207 ms |
196836 KB |
Output is correct |
39 |
Correct |
201 ms |
196924 KB |
Output is correct |
40 |
Correct |
200 ms |
196804 KB |
Output is correct |
41 |
Correct |
203 ms |
196852 KB |
Output is correct |
42 |
Correct |
208 ms |
196896 KB |
Output is correct |
43 |
Correct |
199 ms |
196852 KB |
Output is correct |
44 |
Correct |
223 ms |
196792 KB |
Output is correct |
45 |
Correct |
214 ms |
196932 KB |
Output is correct |
46 |
Correct |
207 ms |
196856 KB |
Output is correct |
47 |
Correct |
262 ms |
196804 KB |
Output is correct |
48 |
Correct |
207 ms |
196852 KB |
Output is correct |
49 |
Correct |
204 ms |
196812 KB |
Output is correct |
50 |
Correct |
208 ms |
196784 KB |
Output is correct |
51 |
Correct |
206 ms |
196800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
196400 KB |
Output is correct |
2 |
Correct |
95 ms |
196320 KB |
Output is correct |
3 |
Correct |
90 ms |
196356 KB |
Output is correct |
4 |
Correct |
89 ms |
196292 KB |
Output is correct |
5 |
Correct |
91 ms |
196388 KB |
Output is correct |
6 |
Correct |
91 ms |
196276 KB |
Output is correct |
7 |
Correct |
96 ms |
196292 KB |
Output is correct |
8 |
Correct |
89 ms |
196384 KB |
Output is correct |
9 |
Correct |
89 ms |
196424 KB |
Output is correct |
10 |
Correct |
91 ms |
196328 KB |
Output is correct |
11 |
Correct |
88 ms |
196288 KB |
Output is correct |
12 |
Correct |
88 ms |
196292 KB |
Output is correct |
13 |
Correct |
89 ms |
196384 KB |
Output is correct |
14 |
Correct |
92 ms |
196384 KB |
Output is correct |
15 |
Correct |
87 ms |
196356 KB |
Output is correct |
16 |
Correct |
90 ms |
196420 KB |
Output is correct |
17 |
Correct |
89 ms |
196400 KB |
Output is correct |
18 |
Correct |
89 ms |
196320 KB |
Output is correct |
19 |
Correct |
88 ms |
196420 KB |
Output is correct |
20 |
Correct |
88 ms |
196332 KB |
Output is correct |
21 |
Correct |
98 ms |
196324 KB |
Output is correct |
22 |
Correct |
103 ms |
196292 KB |
Output is correct |
23 |
Correct |
99 ms |
196404 KB |
Output is correct |
24 |
Correct |
89 ms |
196428 KB |
Output is correct |
25 |
Correct |
89 ms |
196328 KB |
Output is correct |
26 |
Correct |
89 ms |
196404 KB |
Output is correct |
27 |
Correct |
204 ms |
196804 KB |
Output is correct |
28 |
Correct |
200 ms |
196860 KB |
Output is correct |
29 |
Correct |
204 ms |
196852 KB |
Output is correct |
30 |
Correct |
203 ms |
196860 KB |
Output is correct |
31 |
Correct |
199 ms |
196804 KB |
Output is correct |
32 |
Correct |
210 ms |
196856 KB |
Output is correct |
33 |
Correct |
206 ms |
196804 KB |
Output is correct |
34 |
Correct |
206 ms |
196904 KB |
Output is correct |
35 |
Correct |
210 ms |
196932 KB |
Output is correct |
36 |
Correct |
201 ms |
196908 KB |
Output is correct |
37 |
Correct |
212 ms |
196856 KB |
Output is correct |
38 |
Correct |
207 ms |
196836 KB |
Output is correct |
39 |
Correct |
201 ms |
196924 KB |
Output is correct |
40 |
Correct |
200 ms |
196804 KB |
Output is correct |
41 |
Correct |
203 ms |
196852 KB |
Output is correct |
42 |
Correct |
208 ms |
196896 KB |
Output is correct |
43 |
Correct |
199 ms |
196852 KB |
Output is correct |
44 |
Correct |
223 ms |
196792 KB |
Output is correct |
45 |
Correct |
214 ms |
196932 KB |
Output is correct |
46 |
Correct |
207 ms |
196856 KB |
Output is correct |
47 |
Correct |
262 ms |
196804 KB |
Output is correct |
48 |
Correct |
207 ms |
196852 KB |
Output is correct |
49 |
Correct |
204 ms |
196812 KB |
Output is correct |
50 |
Correct |
208 ms |
196784 KB |
Output is correct |
51 |
Correct |
206 ms |
196800 KB |
Output is correct |
52 |
Incorrect |
295 ms |
202372 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |