#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <cstring>
#include <unordered_map>
using namespace std;
typedef int ll;
#define endl '\n'
int main(){
ll m, l;
cin >> m >> l;
vector<ll>a(2 * m + 1);
for(auto &i: a)
cin >> i;
ll s1 = 0, s2 = 0;
for(int i = -m; i <= 0; i++)
s1 += i * a[i + m];
for(int i = 0; i <= m; i++)
s2 += i * a[i + m];
if(l < s1 || l > s2){
cout << "impossible" << endl;
return 0;
}
ll add = abs(s1) + 1;
vector<ll>dp(add + s2 + 10, -1e9), dp2(add + s2 + 10);
dp[0 + add] = 0;
for(int i = 0; i < 2 * m + 1; i++){
ll num = 0;
if(i < m)
num = -(m - i);
else
num = i - m;
for(auto &j : dp2)
j = -1e9;
dp2[0 + add] = 0;
for(int j = 0; j <= a[i]; j++){
ll sum = num * j;
for(int num2 = s1; num2 <= s2; num2++){
if(num2 - sum < s1 || num2 - sum > s2 || dp[num2 + add - sum] == (ll)(-1e9))
continue;
dp2[num2 + add] = max(dp2[num2 + add], j + dp[num2 + add - sum]);
}
}
dp = dp2;
}
if(dp[l + add] == (ll)(-1e9))
cout << "impossible" << endl;
else
cout << dp[l + add] << endl;
return 0;
}
/*
1 5
6 0 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
254 ms |
844 KB |
Output is correct |
7 |
Correct |
46 ms |
468 KB |
Output is correct |
8 |
Correct |
225 ms |
788 KB |
Output is correct |
9 |
Correct |
773 ms |
1252 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
254 ms |
844 KB |
Output is correct |
7 |
Correct |
46 ms |
468 KB |
Output is correct |
8 |
Correct |
225 ms |
788 KB |
Output is correct |
9 |
Correct |
773 ms |
1252 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
249 ms |
816 KB |
Output is correct |
18 |
Correct |
46 ms |
468 KB |
Output is correct |
19 |
Correct |
218 ms |
780 KB |
Output is correct |
20 |
Correct |
758 ms |
1240 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5055 ms |
4180 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
254 ms |
844 KB |
Output is correct |
7 |
Correct |
46 ms |
468 KB |
Output is correct |
8 |
Correct |
225 ms |
788 KB |
Output is correct |
9 |
Correct |
773 ms |
1252 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
254 ms |
844 KB |
Output is correct |
7 |
Correct |
46 ms |
468 KB |
Output is correct |
8 |
Correct |
225 ms |
788 KB |
Output is correct |
9 |
Correct |
773 ms |
1252 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
249 ms |
816 KB |
Output is correct |
18 |
Correct |
46 ms |
468 KB |
Output is correct |
19 |
Correct |
218 ms |
780 KB |
Output is correct |
20 |
Correct |
758 ms |
1240 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5055 ms |
4180 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
254 ms |
844 KB |
Output is correct |
7 |
Correct |
46 ms |
468 KB |
Output is correct |
8 |
Correct |
225 ms |
788 KB |
Output is correct |
9 |
Correct |
773 ms |
1252 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
249 ms |
816 KB |
Output is correct |
18 |
Correct |
46 ms |
468 KB |
Output is correct |
19 |
Correct |
218 ms |
780 KB |
Output is correct |
20 |
Correct |
758 ms |
1240 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5055 ms |
4180 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |