#include <bits/stdc++.h>
using namespace std;
const int MAX_M = 300;
const int MAX_S = 3e5;
const int MIN_S = -MAX_S;
const long long INF = 1e18;
int a[2 * MAX_M + 1];
long long maxObj[MAX_S - MIN_S + 1];
int main() {
int m, l;
cin >> m >> l;
for ( int i = 0; i <= 2 * m; i++ )
cin >> a[i];
for ( int s = 0; s <= MAX_S - MIN_S; s++ )
maxObj[s] = -INF;
maxObj[0 - MIN_S] = 0;
for ( int i = 0; i <= 2 * m; i++ ) {
int x = i - m;
for ( int j = 1; j <= a[i] && j * x <= MAX_S && j * x >= MIN_S; j++ ) {
if ( x > 0 ) {
for ( int s = MAX_S - MIN_S; s >= x; s-- )
maxObj[s] = max( maxObj[s], maxObj[s - x] + 1 );
} else {
for ( int s = x; s <= MAX_S - MIN_S; s++ )
maxObj[s] = max( maxObj[s], maxObj[s - x] + 1 );
}
}
}
if ( l < MIN_S || l > MAX_S || maxObj[l - MIN_S] < 0 )
cout << "impossible\n";
else
cout << maxObj[l - MIN_S] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4952 KB |
Output is correct |
2 |
Correct |
5 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
29 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4980 KB |
Output is correct |
6 |
Correct |
1206 ms |
5120 KB |
Output is correct |
7 |
Correct |
476 ms |
5200 KB |
Output is correct |
8 |
Correct |
1167 ms |
5116 KB |
Output is correct |
9 |
Correct |
2194 ms |
5116 KB |
Output is correct |
10 |
Correct |
54 ms |
4956 KB |
Output is correct |
11 |
Correct |
40 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4952 KB |
Output is correct |
2 |
Correct |
5 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
29 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4980 KB |
Output is correct |
6 |
Correct |
1206 ms |
5120 KB |
Output is correct |
7 |
Correct |
476 ms |
5200 KB |
Output is correct |
8 |
Correct |
1167 ms |
5116 KB |
Output is correct |
9 |
Correct |
2194 ms |
5116 KB |
Output is correct |
10 |
Correct |
54 ms |
4956 KB |
Output is correct |
11 |
Correct |
40 ms |
4952 KB |
Output is correct |
12 |
Correct |
6 ms |
4956 KB |
Output is correct |
13 |
Correct |
5 ms |
4980 KB |
Output is correct |
14 |
Correct |
4 ms |
5136 KB |
Output is correct |
15 |
Correct |
30 ms |
4952 KB |
Output is correct |
16 |
Correct |
1 ms |
4952 KB |
Output is correct |
17 |
Correct |
1344 ms |
5116 KB |
Output is correct |
18 |
Correct |
475 ms |
4956 KB |
Output is correct |
19 |
Correct |
1161 ms |
5120 KB |
Output is correct |
20 |
Correct |
2170 ms |
5112 KB |
Output is correct |
21 |
Correct |
54 ms |
4956 KB |
Output is correct |
22 |
Correct |
40 ms |
4952 KB |
Output is correct |
23 |
Correct |
1 ms |
4956 KB |
Output is correct |
24 |
Correct |
4541 ms |
5116 KB |
Output is correct |
25 |
Correct |
1664 ms |
5116 KB |
Output is correct |
26 |
Execution timed out |
5067 ms |
4956 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4952 KB |
Output is correct |
2 |
Correct |
5 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
29 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4980 KB |
Output is correct |
6 |
Correct |
1206 ms |
5120 KB |
Output is correct |
7 |
Correct |
476 ms |
5200 KB |
Output is correct |
8 |
Correct |
1167 ms |
5116 KB |
Output is correct |
9 |
Correct |
2194 ms |
5116 KB |
Output is correct |
10 |
Correct |
54 ms |
4956 KB |
Output is correct |
11 |
Correct |
40 ms |
4952 KB |
Output is correct |
12 |
Correct |
29 ms |
4956 KB |
Output is correct |
13 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4952 KB |
Output is correct |
2 |
Correct |
5 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
29 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4980 KB |
Output is correct |
6 |
Correct |
1206 ms |
5120 KB |
Output is correct |
7 |
Correct |
476 ms |
5200 KB |
Output is correct |
8 |
Correct |
1167 ms |
5116 KB |
Output is correct |
9 |
Correct |
2194 ms |
5116 KB |
Output is correct |
10 |
Correct |
54 ms |
4956 KB |
Output is correct |
11 |
Correct |
40 ms |
4952 KB |
Output is correct |
12 |
Correct |
6 ms |
4956 KB |
Output is correct |
13 |
Correct |
5 ms |
4980 KB |
Output is correct |
14 |
Correct |
4 ms |
5136 KB |
Output is correct |
15 |
Correct |
30 ms |
4952 KB |
Output is correct |
16 |
Correct |
1 ms |
4952 KB |
Output is correct |
17 |
Correct |
1344 ms |
5116 KB |
Output is correct |
18 |
Correct |
475 ms |
4956 KB |
Output is correct |
19 |
Correct |
1161 ms |
5120 KB |
Output is correct |
20 |
Correct |
2170 ms |
5112 KB |
Output is correct |
21 |
Correct |
54 ms |
4956 KB |
Output is correct |
22 |
Correct |
40 ms |
4952 KB |
Output is correct |
23 |
Correct |
1 ms |
4956 KB |
Output is correct |
24 |
Correct |
4541 ms |
5116 KB |
Output is correct |
25 |
Correct |
1664 ms |
5116 KB |
Output is correct |
26 |
Execution timed out |
5067 ms |
4956 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4952 KB |
Output is correct |
2 |
Correct |
5 ms |
4956 KB |
Output is correct |
3 |
Correct |
4 ms |
4956 KB |
Output is correct |
4 |
Correct |
29 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4980 KB |
Output is correct |
6 |
Correct |
1206 ms |
5120 KB |
Output is correct |
7 |
Correct |
476 ms |
5200 KB |
Output is correct |
8 |
Correct |
1167 ms |
5116 KB |
Output is correct |
9 |
Correct |
2194 ms |
5116 KB |
Output is correct |
10 |
Correct |
54 ms |
4956 KB |
Output is correct |
11 |
Correct |
40 ms |
4952 KB |
Output is correct |
12 |
Correct |
6 ms |
4956 KB |
Output is correct |
13 |
Correct |
5 ms |
4980 KB |
Output is correct |
14 |
Correct |
4 ms |
5136 KB |
Output is correct |
15 |
Correct |
30 ms |
4952 KB |
Output is correct |
16 |
Correct |
1 ms |
4952 KB |
Output is correct |
17 |
Correct |
1344 ms |
5116 KB |
Output is correct |
18 |
Correct |
475 ms |
4956 KB |
Output is correct |
19 |
Correct |
1161 ms |
5120 KB |
Output is correct |
20 |
Correct |
2170 ms |
5112 KB |
Output is correct |
21 |
Correct |
54 ms |
4956 KB |
Output is correct |
22 |
Correct |
40 ms |
4952 KB |
Output is correct |
23 |
Correct |
1 ms |
4956 KB |
Output is correct |
24 |
Correct |
4541 ms |
5116 KB |
Output is correct |
25 |
Correct |
1664 ms |
5116 KB |
Output is correct |
26 |
Execution timed out |
5067 ms |
4956 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |