// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 5005;
int n;
int a[MAXN];
int lft[MAXN], rht[MAXN];
int dp[MAXN][MAXN * 4];
int ans;
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> n;
ll sm = 0;
REP (i, 0, n) {
cin >> a[i];
sm += max(0, a[i]);
}
REP (i, 0, n) {
if (a[i] == -1) {
lft[i] = i;
} else {
lft[i] = i == 0 ? -INF : lft[i - 1];
}
}
rht[n] = INF;
RREP (i, n - 1, 0) {
if (a[i] == -1) {
rht[i] = i;
} else {
rht[i] = rht[i + 1];
}
}
REP (i, 0, MAXN) {
REP (j, 0, MAXN * 4) {
dp[i][j] = -INF;
}
}
dp[0][0] = 0;
REP (i, 0, n) {
REP (j, 0, n * 2 + 1) {
mxto(dp[i + 1][j + 1], dp[i][j]);
if (a[i] <= 0) {
continue;
}
REP (k, 1, a[i] + 1) {
int near = min(i - lft[i], rht[i] - i);
ll nj = j + (ll) near * 2 * (k - 1);
if (nj > i * 2) {
break;
}
mxto(ans, dp[i][j] + k);
if (lft[i] != -INF) {
mxto(dp[i + 1][nj + i - lft[i] + i + 1 - lft[i]],
dp[i][j] + k);
}
if (rht[i] != INF) {
RREP (l, rht[i], i + 1) {
mxto(dp[l][nj + rht[i] - i + rht[i] - l], dp[i][j] + k);
}
}
}
}
}
cout << sm - ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
392496 KB |
Output is correct |
2 |
Correct |
173 ms |
392476 KB |
Output is correct |
3 |
Correct |
180 ms |
392464 KB |
Output is correct |
4 |
Correct |
172 ms |
392568 KB |
Output is correct |
5 |
Correct |
169 ms |
392472 KB |
Output is correct |
6 |
Correct |
186 ms |
392448 KB |
Output is correct |
7 |
Correct |
175 ms |
392468 KB |
Output is correct |
8 |
Correct |
174 ms |
392404 KB |
Output is correct |
9 |
Correct |
169 ms |
392392 KB |
Output is correct |
10 |
Correct |
177 ms |
392404 KB |
Output is correct |
11 |
Correct |
203 ms |
392392 KB |
Output is correct |
12 |
Correct |
182 ms |
392368 KB |
Output is correct |
13 |
Correct |
171 ms |
392408 KB |
Output is correct |
14 |
Correct |
175 ms |
392472 KB |
Output is correct |
15 |
Correct |
176 ms |
392416 KB |
Output is correct |
16 |
Correct |
211 ms |
392440 KB |
Output is correct |
17 |
Correct |
174 ms |
392396 KB |
Output is correct |
18 |
Correct |
175 ms |
392360 KB |
Output is correct |
19 |
Correct |
194 ms |
392452 KB |
Output is correct |
20 |
Correct |
165 ms |
392488 KB |
Output is correct |
21 |
Correct |
171 ms |
392396 KB |
Output is correct |
22 |
Correct |
174 ms |
392492 KB |
Output is correct |
23 |
Correct |
189 ms |
392488 KB |
Output is correct |
24 |
Correct |
183 ms |
392492 KB |
Output is correct |
25 |
Correct |
169 ms |
392484 KB |
Output is correct |
26 |
Correct |
191 ms |
392404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
392496 KB |
Output is correct |
2 |
Correct |
173 ms |
392476 KB |
Output is correct |
3 |
Correct |
180 ms |
392464 KB |
Output is correct |
4 |
Correct |
172 ms |
392568 KB |
Output is correct |
5 |
Correct |
169 ms |
392472 KB |
Output is correct |
6 |
Correct |
186 ms |
392448 KB |
Output is correct |
7 |
Correct |
175 ms |
392468 KB |
Output is correct |
8 |
Correct |
174 ms |
392404 KB |
Output is correct |
9 |
Correct |
169 ms |
392392 KB |
Output is correct |
10 |
Correct |
177 ms |
392404 KB |
Output is correct |
11 |
Correct |
203 ms |
392392 KB |
Output is correct |
12 |
Correct |
182 ms |
392368 KB |
Output is correct |
13 |
Correct |
171 ms |
392408 KB |
Output is correct |
14 |
Correct |
175 ms |
392472 KB |
Output is correct |
15 |
Correct |
176 ms |
392416 KB |
Output is correct |
16 |
Correct |
211 ms |
392440 KB |
Output is correct |
17 |
Correct |
174 ms |
392396 KB |
Output is correct |
18 |
Correct |
175 ms |
392360 KB |
Output is correct |
19 |
Correct |
194 ms |
392452 KB |
Output is correct |
20 |
Correct |
165 ms |
392488 KB |
Output is correct |
21 |
Correct |
171 ms |
392396 KB |
Output is correct |
22 |
Correct |
174 ms |
392492 KB |
Output is correct |
23 |
Correct |
189 ms |
392488 KB |
Output is correct |
24 |
Correct |
183 ms |
392492 KB |
Output is correct |
25 |
Correct |
169 ms |
392484 KB |
Output is correct |
26 |
Correct |
191 ms |
392404 KB |
Output is correct |
27 |
Correct |
170 ms |
392532 KB |
Output is correct |
28 |
Correct |
171 ms |
392400 KB |
Output is correct |
29 |
Correct |
169 ms |
392440 KB |
Output is correct |
30 |
Correct |
165 ms |
392448 KB |
Output is correct |
31 |
Correct |
166 ms |
392464 KB |
Output is correct |
32 |
Correct |
162 ms |
392432 KB |
Output is correct |
33 |
Correct |
179 ms |
392488 KB |
Output is correct |
34 |
Correct |
173 ms |
392392 KB |
Output is correct |
35 |
Correct |
171 ms |
392464 KB |
Output is correct |
36 |
Correct |
193 ms |
392464 KB |
Output is correct |
37 |
Correct |
164 ms |
392500 KB |
Output is correct |
38 |
Correct |
169 ms |
392448 KB |
Output is correct |
39 |
Correct |
170 ms |
392416 KB |
Output is correct |
40 |
Correct |
181 ms |
392408 KB |
Output is correct |
41 |
Correct |
190 ms |
392476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
392496 KB |
Output is correct |
2 |
Correct |
173 ms |
392476 KB |
Output is correct |
3 |
Correct |
180 ms |
392464 KB |
Output is correct |
4 |
Correct |
172 ms |
392568 KB |
Output is correct |
5 |
Correct |
169 ms |
392472 KB |
Output is correct |
6 |
Correct |
186 ms |
392448 KB |
Output is correct |
7 |
Correct |
175 ms |
392468 KB |
Output is correct |
8 |
Correct |
174 ms |
392404 KB |
Output is correct |
9 |
Correct |
169 ms |
392392 KB |
Output is correct |
10 |
Correct |
177 ms |
392404 KB |
Output is correct |
11 |
Correct |
203 ms |
392392 KB |
Output is correct |
12 |
Correct |
182 ms |
392368 KB |
Output is correct |
13 |
Correct |
171 ms |
392408 KB |
Output is correct |
14 |
Correct |
175 ms |
392472 KB |
Output is correct |
15 |
Correct |
176 ms |
392416 KB |
Output is correct |
16 |
Correct |
211 ms |
392440 KB |
Output is correct |
17 |
Correct |
174 ms |
392396 KB |
Output is correct |
18 |
Correct |
175 ms |
392360 KB |
Output is correct |
19 |
Correct |
194 ms |
392452 KB |
Output is correct |
20 |
Correct |
165 ms |
392488 KB |
Output is correct |
21 |
Correct |
171 ms |
392396 KB |
Output is correct |
22 |
Correct |
174 ms |
392492 KB |
Output is correct |
23 |
Correct |
189 ms |
392488 KB |
Output is correct |
24 |
Correct |
183 ms |
392492 KB |
Output is correct |
25 |
Correct |
169 ms |
392484 KB |
Output is correct |
26 |
Correct |
191 ms |
392404 KB |
Output is correct |
27 |
Correct |
170 ms |
392532 KB |
Output is correct |
28 |
Correct |
171 ms |
392400 KB |
Output is correct |
29 |
Correct |
169 ms |
392440 KB |
Output is correct |
30 |
Correct |
165 ms |
392448 KB |
Output is correct |
31 |
Correct |
166 ms |
392464 KB |
Output is correct |
32 |
Correct |
162 ms |
392432 KB |
Output is correct |
33 |
Correct |
179 ms |
392488 KB |
Output is correct |
34 |
Correct |
173 ms |
392392 KB |
Output is correct |
35 |
Correct |
171 ms |
392464 KB |
Output is correct |
36 |
Correct |
193 ms |
392464 KB |
Output is correct |
37 |
Correct |
164 ms |
392500 KB |
Output is correct |
38 |
Correct |
169 ms |
392448 KB |
Output is correct |
39 |
Correct |
170 ms |
392416 KB |
Output is correct |
40 |
Correct |
181 ms |
392408 KB |
Output is correct |
41 |
Correct |
190 ms |
392476 KB |
Output is correct |
42 |
Correct |
171 ms |
392544 KB |
Output is correct |
43 |
Correct |
189 ms |
392580 KB |
Output is correct |
44 |
Correct |
174 ms |
392424 KB |
Output is correct |
45 |
Correct |
169 ms |
392424 KB |
Output is correct |
46 |
Correct |
168 ms |
392396 KB |
Output is correct |
47 |
Correct |
169 ms |
392424 KB |
Output is correct |
48 |
Correct |
167 ms |
392584 KB |
Output is correct |
49 |
Correct |
169 ms |
392460 KB |
Output is correct |
50 |
Correct |
172 ms |
392456 KB |
Output is correct |
51 |
Correct |
169 ms |
392460 KB |
Output is correct |
52 |
Correct |
168 ms |
392396 KB |
Output is correct |
53 |
Correct |
180 ms |
392428 KB |
Output is correct |
54 |
Correct |
180 ms |
392464 KB |
Output is correct |
55 |
Correct |
192 ms |
392460 KB |
Output is correct |
56 |
Correct |
172 ms |
392428 KB |
Output is correct |
57 |
Correct |
179 ms |
392412 KB |
Output is correct |
58 |
Correct |
166 ms |
392464 KB |
Output is correct |
59 |
Correct |
167 ms |
392472 KB |
Output is correct |
60 |
Correct |
183 ms |
392396 KB |
Output is correct |
61 |
Correct |
180 ms |
392472 KB |
Output is correct |
62 |
Correct |
173 ms |
392392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
392496 KB |
Output is correct |
2 |
Correct |
173 ms |
392476 KB |
Output is correct |
3 |
Correct |
180 ms |
392464 KB |
Output is correct |
4 |
Correct |
172 ms |
392568 KB |
Output is correct |
5 |
Correct |
169 ms |
392472 KB |
Output is correct |
6 |
Correct |
186 ms |
392448 KB |
Output is correct |
7 |
Correct |
175 ms |
392468 KB |
Output is correct |
8 |
Correct |
174 ms |
392404 KB |
Output is correct |
9 |
Correct |
169 ms |
392392 KB |
Output is correct |
10 |
Correct |
177 ms |
392404 KB |
Output is correct |
11 |
Correct |
203 ms |
392392 KB |
Output is correct |
12 |
Correct |
182 ms |
392368 KB |
Output is correct |
13 |
Correct |
171 ms |
392408 KB |
Output is correct |
14 |
Correct |
175 ms |
392472 KB |
Output is correct |
15 |
Correct |
176 ms |
392416 KB |
Output is correct |
16 |
Correct |
211 ms |
392440 KB |
Output is correct |
17 |
Correct |
174 ms |
392396 KB |
Output is correct |
18 |
Correct |
175 ms |
392360 KB |
Output is correct |
19 |
Correct |
194 ms |
392452 KB |
Output is correct |
20 |
Correct |
165 ms |
392488 KB |
Output is correct |
21 |
Correct |
171 ms |
392396 KB |
Output is correct |
22 |
Correct |
174 ms |
392492 KB |
Output is correct |
23 |
Correct |
189 ms |
392488 KB |
Output is correct |
24 |
Correct |
183 ms |
392492 KB |
Output is correct |
25 |
Correct |
169 ms |
392484 KB |
Output is correct |
26 |
Correct |
191 ms |
392404 KB |
Output is correct |
27 |
Correct |
170 ms |
392532 KB |
Output is correct |
28 |
Correct |
171 ms |
392400 KB |
Output is correct |
29 |
Correct |
169 ms |
392440 KB |
Output is correct |
30 |
Correct |
165 ms |
392448 KB |
Output is correct |
31 |
Correct |
166 ms |
392464 KB |
Output is correct |
32 |
Correct |
162 ms |
392432 KB |
Output is correct |
33 |
Correct |
179 ms |
392488 KB |
Output is correct |
34 |
Correct |
173 ms |
392392 KB |
Output is correct |
35 |
Correct |
171 ms |
392464 KB |
Output is correct |
36 |
Correct |
193 ms |
392464 KB |
Output is correct |
37 |
Correct |
164 ms |
392500 KB |
Output is correct |
38 |
Correct |
169 ms |
392448 KB |
Output is correct |
39 |
Correct |
170 ms |
392416 KB |
Output is correct |
40 |
Correct |
181 ms |
392408 KB |
Output is correct |
41 |
Correct |
190 ms |
392476 KB |
Output is correct |
42 |
Correct |
171 ms |
392544 KB |
Output is correct |
43 |
Correct |
189 ms |
392580 KB |
Output is correct |
44 |
Correct |
174 ms |
392424 KB |
Output is correct |
45 |
Correct |
169 ms |
392424 KB |
Output is correct |
46 |
Correct |
168 ms |
392396 KB |
Output is correct |
47 |
Correct |
169 ms |
392424 KB |
Output is correct |
48 |
Correct |
167 ms |
392584 KB |
Output is correct |
49 |
Correct |
169 ms |
392460 KB |
Output is correct |
50 |
Correct |
172 ms |
392456 KB |
Output is correct |
51 |
Correct |
169 ms |
392460 KB |
Output is correct |
52 |
Correct |
168 ms |
392396 KB |
Output is correct |
53 |
Correct |
180 ms |
392428 KB |
Output is correct |
54 |
Correct |
180 ms |
392464 KB |
Output is correct |
55 |
Correct |
192 ms |
392460 KB |
Output is correct |
56 |
Correct |
172 ms |
392428 KB |
Output is correct |
57 |
Correct |
179 ms |
392412 KB |
Output is correct |
58 |
Correct |
166 ms |
392464 KB |
Output is correct |
59 |
Correct |
167 ms |
392472 KB |
Output is correct |
60 |
Correct |
183 ms |
392396 KB |
Output is correct |
61 |
Correct |
180 ms |
392472 KB |
Output is correct |
62 |
Correct |
173 ms |
392392 KB |
Output is correct |
63 |
Correct |
400 ms |
392568 KB |
Output is correct |
64 |
Correct |
800 ms |
392524 KB |
Output is correct |
65 |
Correct |
456 ms |
392528 KB |
Output is correct |
66 |
Correct |
528 ms |
392548 KB |
Output is correct |
67 |
Correct |
790 ms |
392492 KB |
Output is correct |
68 |
Correct |
463 ms |
392676 KB |
Output is correct |
69 |
Correct |
528 ms |
392548 KB |
Output is correct |
70 |
Correct |
650 ms |
392552 KB |
Output is correct |
71 |
Execution timed out |
3075 ms |
392524 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
392496 KB |
Output is correct |
2 |
Correct |
173 ms |
392476 KB |
Output is correct |
3 |
Correct |
180 ms |
392464 KB |
Output is correct |
4 |
Correct |
172 ms |
392568 KB |
Output is correct |
5 |
Correct |
169 ms |
392472 KB |
Output is correct |
6 |
Correct |
186 ms |
392448 KB |
Output is correct |
7 |
Correct |
175 ms |
392468 KB |
Output is correct |
8 |
Correct |
174 ms |
392404 KB |
Output is correct |
9 |
Correct |
169 ms |
392392 KB |
Output is correct |
10 |
Correct |
177 ms |
392404 KB |
Output is correct |
11 |
Correct |
203 ms |
392392 KB |
Output is correct |
12 |
Correct |
182 ms |
392368 KB |
Output is correct |
13 |
Correct |
171 ms |
392408 KB |
Output is correct |
14 |
Correct |
175 ms |
392472 KB |
Output is correct |
15 |
Correct |
176 ms |
392416 KB |
Output is correct |
16 |
Correct |
211 ms |
392440 KB |
Output is correct |
17 |
Correct |
174 ms |
392396 KB |
Output is correct |
18 |
Correct |
175 ms |
392360 KB |
Output is correct |
19 |
Correct |
194 ms |
392452 KB |
Output is correct |
20 |
Correct |
165 ms |
392488 KB |
Output is correct |
21 |
Correct |
171 ms |
392396 KB |
Output is correct |
22 |
Correct |
174 ms |
392492 KB |
Output is correct |
23 |
Correct |
189 ms |
392488 KB |
Output is correct |
24 |
Correct |
183 ms |
392492 KB |
Output is correct |
25 |
Correct |
169 ms |
392484 KB |
Output is correct |
26 |
Correct |
191 ms |
392404 KB |
Output is correct |
27 |
Correct |
170 ms |
392532 KB |
Output is correct |
28 |
Correct |
171 ms |
392400 KB |
Output is correct |
29 |
Correct |
169 ms |
392440 KB |
Output is correct |
30 |
Correct |
165 ms |
392448 KB |
Output is correct |
31 |
Correct |
166 ms |
392464 KB |
Output is correct |
32 |
Correct |
162 ms |
392432 KB |
Output is correct |
33 |
Correct |
179 ms |
392488 KB |
Output is correct |
34 |
Correct |
173 ms |
392392 KB |
Output is correct |
35 |
Correct |
171 ms |
392464 KB |
Output is correct |
36 |
Correct |
193 ms |
392464 KB |
Output is correct |
37 |
Correct |
164 ms |
392500 KB |
Output is correct |
38 |
Correct |
169 ms |
392448 KB |
Output is correct |
39 |
Correct |
170 ms |
392416 KB |
Output is correct |
40 |
Correct |
181 ms |
392408 KB |
Output is correct |
41 |
Correct |
190 ms |
392476 KB |
Output is correct |
42 |
Correct |
171 ms |
392544 KB |
Output is correct |
43 |
Correct |
189 ms |
392580 KB |
Output is correct |
44 |
Correct |
174 ms |
392424 KB |
Output is correct |
45 |
Correct |
169 ms |
392424 KB |
Output is correct |
46 |
Correct |
168 ms |
392396 KB |
Output is correct |
47 |
Correct |
169 ms |
392424 KB |
Output is correct |
48 |
Correct |
167 ms |
392584 KB |
Output is correct |
49 |
Correct |
169 ms |
392460 KB |
Output is correct |
50 |
Correct |
172 ms |
392456 KB |
Output is correct |
51 |
Correct |
169 ms |
392460 KB |
Output is correct |
52 |
Correct |
168 ms |
392396 KB |
Output is correct |
53 |
Correct |
180 ms |
392428 KB |
Output is correct |
54 |
Correct |
180 ms |
392464 KB |
Output is correct |
55 |
Correct |
192 ms |
392460 KB |
Output is correct |
56 |
Correct |
172 ms |
392428 KB |
Output is correct |
57 |
Correct |
179 ms |
392412 KB |
Output is correct |
58 |
Correct |
166 ms |
392464 KB |
Output is correct |
59 |
Correct |
167 ms |
392472 KB |
Output is correct |
60 |
Correct |
183 ms |
392396 KB |
Output is correct |
61 |
Correct |
180 ms |
392472 KB |
Output is correct |
62 |
Correct |
173 ms |
392392 KB |
Output is correct |
63 |
Correct |
400 ms |
392568 KB |
Output is correct |
64 |
Correct |
800 ms |
392524 KB |
Output is correct |
65 |
Correct |
456 ms |
392528 KB |
Output is correct |
66 |
Correct |
528 ms |
392548 KB |
Output is correct |
67 |
Correct |
790 ms |
392492 KB |
Output is correct |
68 |
Correct |
463 ms |
392676 KB |
Output is correct |
69 |
Correct |
528 ms |
392548 KB |
Output is correct |
70 |
Correct |
650 ms |
392552 KB |
Output is correct |
71 |
Execution timed out |
3075 ms |
392524 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |