#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#define int long long
using namespace std;
const int M = 300 + 11;
const int X = M * M;
const int INF = 1LL << 60;
int a[M * 2];
int s[M * 2];
int dp[M * 2][X];
int32_t main(){
int m, L; cin >> m >> L;
for(int i = 0; i <= m * 2; i++) cin >> a[i];
int ans = a[m];
for(int i = m + 1; i <= m * 2; i++) s[i] = min(L, s[i - 1] + (i - m) * a[i]);
for(int i = m; i <= m * 2; i++)
fill(dp[i], dp[i] + X, -INF);
dp[m][0] = 0;
for(int i = m + 1; i <= m * 2; i++){
for(int j = 0; j < m * m; j++){
for(int k = 0; k < m * m; k++){
int vj = s[i - 1] - j, vk = s[i] - k;
if(vj > vk || (vk - vj) % (i - m) != 0 || (vk - vj) / (i - m) > a[i]) continue;
dp[i][k] = max(dp[i][k], dp[i - 1][j] + (vk - vj) / (i - m));
}
}
}
if(s[m * 2] < L || L < 0){
cout << "impossible" << endl;
return 0;
}
if(dp[m * 2][0] < 0){
cout << "impossible" << endl;
}else{
cout << ans + dp[m * 2][0] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8532 KB |
Output is correct |
2 |
Correct |
161 ms |
23776 KB |
Output is correct |
3 |
Correct |
101 ms |
23764 KB |
Output is correct |
4 |
Correct |
128 ms |
23776 KB |
Output is correct |
5 |
Correct |
143 ms |
23780 KB |
Output is correct |
6 |
Correct |
82 ms |
23780 KB |
Output is correct |
7 |
Correct |
76 ms |
23780 KB |
Output is correct |
8 |
Correct |
79 ms |
23780 KB |
Output is correct |
9 |
Correct |
98 ms |
23780 KB |
Output is correct |
10 |
Correct |
126 ms |
23780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8532 KB |
Output is correct |
2 |
Correct |
161 ms |
23776 KB |
Output is correct |
3 |
Correct |
101 ms |
23764 KB |
Output is correct |
4 |
Correct |
128 ms |
23776 KB |
Output is correct |
5 |
Correct |
143 ms |
23780 KB |
Output is correct |
6 |
Correct |
82 ms |
23780 KB |
Output is correct |
7 |
Correct |
76 ms |
23780 KB |
Output is correct |
8 |
Correct |
79 ms |
23780 KB |
Output is correct |
9 |
Correct |
98 ms |
23780 KB |
Output is correct |
10 |
Correct |
126 ms |
23780 KB |
Output is correct |
11 |
Incorrect |
1 ms |
2488 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8532 KB |
Output is correct |
2 |
Correct |
161 ms |
23776 KB |
Output is correct |
3 |
Correct |
101 ms |
23764 KB |
Output is correct |
4 |
Correct |
128 ms |
23776 KB |
Output is correct |
5 |
Correct |
143 ms |
23780 KB |
Output is correct |
6 |
Correct |
82 ms |
23780 KB |
Output is correct |
7 |
Correct |
76 ms |
23780 KB |
Output is correct |
8 |
Correct |
79 ms |
23780 KB |
Output is correct |
9 |
Correct |
98 ms |
23780 KB |
Output is correct |
10 |
Correct |
126 ms |
23780 KB |
Output is correct |
11 |
Correct |
3 ms |
8532 KB |
Output is correct |
12 |
Correct |
161 ms |
23780 KB |
Output is correct |
13 |
Correct |
103 ms |
23776 KB |
Output is correct |
14 |
Correct |
127 ms |
23780 KB |
Output is correct |
15 |
Correct |
144 ms |
23780 KB |
Output is correct |
16 |
Correct |
82 ms |
23764 KB |
Output is correct |
17 |
Correct |
77 ms |
23732 KB |
Output is correct |
18 |
Correct |
79 ms |
23796 KB |
Output is correct |
19 |
Correct |
98 ms |
23776 KB |
Output is correct |
20 |
Correct |
126 ms |
23780 KB |
Output is correct |
21 |
Correct |
906 ms |
38920 KB |
Output is correct |
22 |
Correct |
895 ms |
38924 KB |
Output is correct |
23 |
Correct |
1732 ms |
38920 KB |
Output is correct |
24 |
Correct |
1420 ms |
38924 KB |
Output is correct |
25 |
Correct |
1735 ms |
38920 KB |
Output is correct |
26 |
Correct |
1389 ms |
38920 KB |
Output is correct |
27 |
Correct |
961 ms |
38920 KB |
Output is correct |
28 |
Correct |
1831 ms |
38920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8532 KB |
Output is correct |
2 |
Correct |
161 ms |
23776 KB |
Output is correct |
3 |
Correct |
101 ms |
23764 KB |
Output is correct |
4 |
Correct |
128 ms |
23776 KB |
Output is correct |
5 |
Correct |
143 ms |
23780 KB |
Output is correct |
6 |
Correct |
82 ms |
23780 KB |
Output is correct |
7 |
Correct |
76 ms |
23780 KB |
Output is correct |
8 |
Correct |
79 ms |
23780 KB |
Output is correct |
9 |
Correct |
98 ms |
23780 KB |
Output is correct |
10 |
Correct |
126 ms |
23780 KB |
Output is correct |
11 |
Correct |
3 ms |
8532 KB |
Output is correct |
12 |
Correct |
161 ms |
23780 KB |
Output is correct |
13 |
Correct |
103 ms |
23776 KB |
Output is correct |
14 |
Correct |
127 ms |
23780 KB |
Output is correct |
15 |
Correct |
144 ms |
23780 KB |
Output is correct |
16 |
Correct |
82 ms |
23764 KB |
Output is correct |
17 |
Correct |
77 ms |
23732 KB |
Output is correct |
18 |
Correct |
79 ms |
23796 KB |
Output is correct |
19 |
Correct |
98 ms |
23776 KB |
Output is correct |
20 |
Correct |
126 ms |
23780 KB |
Output is correct |
21 |
Correct |
906 ms |
38920 KB |
Output is correct |
22 |
Correct |
895 ms |
38924 KB |
Output is correct |
23 |
Correct |
1732 ms |
38920 KB |
Output is correct |
24 |
Correct |
1420 ms |
38924 KB |
Output is correct |
25 |
Correct |
1735 ms |
38920 KB |
Output is correct |
26 |
Correct |
1389 ms |
38920 KB |
Output is correct |
27 |
Correct |
961 ms |
38920 KB |
Output is correct |
28 |
Correct |
1831 ms |
38920 KB |
Output is correct |
29 |
Correct |
4 ms |
8532 KB |
Output is correct |
30 |
Correct |
163 ms |
23780 KB |
Output is correct |
31 |
Correct |
103 ms |
23780 KB |
Output is correct |
32 |
Correct |
126 ms |
23784 KB |
Output is correct |
33 |
Correct |
144 ms |
23780 KB |
Output is correct |
34 |
Correct |
82 ms |
23776 KB |
Output is correct |
35 |
Correct |
77 ms |
23764 KB |
Output is correct |
36 |
Correct |
77 ms |
23780 KB |
Output is correct |
37 |
Correct |
99 ms |
23780 KB |
Output is correct |
38 |
Correct |
126 ms |
23764 KB |
Output is correct |
39 |
Correct |
906 ms |
38924 KB |
Output is correct |
40 |
Correct |
889 ms |
38936 KB |
Output is correct |
41 |
Correct |
1735 ms |
38924 KB |
Output is correct |
42 |
Correct |
1420 ms |
38940 KB |
Output is correct |
43 |
Correct |
1741 ms |
38920 KB |
Output is correct |
44 |
Correct |
1384 ms |
39016 KB |
Output is correct |
45 |
Correct |
937 ms |
38924 KB |
Output is correct |
46 |
Correct |
1822 ms |
38924 KB |
Output is correct |
47 |
Execution timed out |
5066 ms |
76708 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8532 KB |
Output is correct |
2 |
Correct |
161 ms |
23776 KB |
Output is correct |
3 |
Correct |
101 ms |
23764 KB |
Output is correct |
4 |
Correct |
128 ms |
23776 KB |
Output is correct |
5 |
Correct |
143 ms |
23780 KB |
Output is correct |
6 |
Correct |
82 ms |
23780 KB |
Output is correct |
7 |
Correct |
76 ms |
23780 KB |
Output is correct |
8 |
Correct |
79 ms |
23780 KB |
Output is correct |
9 |
Correct |
98 ms |
23780 KB |
Output is correct |
10 |
Correct |
126 ms |
23780 KB |
Output is correct |
11 |
Correct |
3 ms |
8532 KB |
Output is correct |
12 |
Correct |
161 ms |
23780 KB |
Output is correct |
13 |
Correct |
103 ms |
23776 KB |
Output is correct |
14 |
Correct |
127 ms |
23780 KB |
Output is correct |
15 |
Correct |
144 ms |
23780 KB |
Output is correct |
16 |
Correct |
82 ms |
23764 KB |
Output is correct |
17 |
Correct |
77 ms |
23732 KB |
Output is correct |
18 |
Correct |
79 ms |
23796 KB |
Output is correct |
19 |
Correct |
98 ms |
23776 KB |
Output is correct |
20 |
Correct |
126 ms |
23780 KB |
Output is correct |
21 |
Correct |
906 ms |
38920 KB |
Output is correct |
22 |
Correct |
895 ms |
38924 KB |
Output is correct |
23 |
Correct |
1732 ms |
38920 KB |
Output is correct |
24 |
Correct |
1420 ms |
38924 KB |
Output is correct |
25 |
Correct |
1735 ms |
38920 KB |
Output is correct |
26 |
Correct |
1389 ms |
38920 KB |
Output is correct |
27 |
Correct |
961 ms |
38920 KB |
Output is correct |
28 |
Correct |
1831 ms |
38920 KB |
Output is correct |
29 |
Correct |
4 ms |
8532 KB |
Output is correct |
30 |
Correct |
163 ms |
23780 KB |
Output is correct |
31 |
Correct |
103 ms |
23780 KB |
Output is correct |
32 |
Correct |
126 ms |
23784 KB |
Output is correct |
33 |
Correct |
144 ms |
23780 KB |
Output is correct |
34 |
Correct |
82 ms |
23776 KB |
Output is correct |
35 |
Correct |
77 ms |
23764 KB |
Output is correct |
36 |
Correct |
77 ms |
23780 KB |
Output is correct |
37 |
Correct |
99 ms |
23780 KB |
Output is correct |
38 |
Correct |
126 ms |
23764 KB |
Output is correct |
39 |
Correct |
906 ms |
38924 KB |
Output is correct |
40 |
Correct |
889 ms |
38936 KB |
Output is correct |
41 |
Correct |
1735 ms |
38924 KB |
Output is correct |
42 |
Correct |
1420 ms |
38940 KB |
Output is correct |
43 |
Correct |
1741 ms |
38920 KB |
Output is correct |
44 |
Correct |
1384 ms |
39016 KB |
Output is correct |
45 |
Correct |
937 ms |
38924 KB |
Output is correct |
46 |
Correct |
1822 ms |
38924 KB |
Output is correct |
47 |
Execution timed out |
5066 ms |
76708 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |