#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
struct chash {
const ll R = chrono::steady_clock::now().time_since_epoch().count();
const ll C = ll(4e18 * acos(0)) + 73;
ll operator()(ll x) {
return __builtin_bswap64((x^R) * C);
}
};
int m;
ll l, a[605];
unordered_map<ll, ll> mem[605];
ll solve(int i, ll s) {
if (i == 2 * m + 1) {
if (s == l) return 0;
return -1e18;
}
if (mem[i].find(s) != mem[i].end()) {
return mem[i][s];
}
ll ans = -1e18;
for (int j = 0; j <= a[i]; j++) {
ans = max(ans, j + solve(i + 1, s + j * (i - m)));
}
return mem[i][s] = ans;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> m >> l;
for (int i = 0; i < 2 * m + 1; i++) {
cin >> a[i];
}
ll ans = solve(0, 0);
if (ans < 0) {
cout << "impossible\n";
} else {
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3146 ms |
143272 KB |
Output is correct |
6 |
Correct |
3310 ms |
144356 KB |
Output is correct |
7 |
Correct |
560 ms |
55324 KB |
Output is correct |
8 |
Correct |
3007 ms |
129012 KB |
Output is correct |
9 |
Execution timed out |
5042 ms |
149712 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3146 ms |
143272 KB |
Output is correct |
6 |
Correct |
3310 ms |
144356 KB |
Output is correct |
7 |
Correct |
560 ms |
55324 KB |
Output is correct |
8 |
Correct |
3007 ms |
129012 KB |
Output is correct |
9 |
Execution timed out |
5042 ms |
149712 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2714 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2714 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2714 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3146 ms |
143272 KB |
Output is correct |
6 |
Correct |
3310 ms |
144356 KB |
Output is correct |
7 |
Correct |
560 ms |
55324 KB |
Output is correct |
8 |
Correct |
3007 ms |
129012 KB |
Output is correct |
9 |
Execution timed out |
5042 ms |
149712 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2714 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3146 ms |
143272 KB |
Output is correct |
6 |
Correct |
3310 ms |
144356 KB |
Output is correct |
7 |
Correct |
560 ms |
55324 KB |
Output is correct |
8 |
Correct |
3007 ms |
129012 KB |
Output is correct |
9 |
Execution timed out |
5042 ms |
149712 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
2714 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3146 ms |
143272 KB |
Output is correct |
6 |
Correct |
3310 ms |
144356 KB |
Output is correct |
7 |
Correct |
560 ms |
55324 KB |
Output is correct |
8 |
Correct |
3007 ms |
129012 KB |
Output is correct |
9 |
Execution timed out |
5042 ms |
149712 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |