#include "bits/stdc++.h"
using namespace std;
using ll = long long;
vector<int> calc(vector<int> x) {
int S = (int)x.size() * 50;
vector<int> dp(S + 1, INT_MIN);
dp[0] = 0;
for(int i = 0; i < (int)x.size(); ++i) {
for(int j = S; j >= 0; --j) {
if(j - x[i] >= 0) if(dp[j - x[i]] != INT_MIN) dp[j] = max(dp[j], dp[j - x[i]] + 1);
}
}
return dp;
}
int main() {
ll l, m; cin >> m >> l;
vector<int> a(2 * m + 1);
for(int i = 0; i < 2 * m + 1; ++i) cin >> a[i];
int ans = INT_MIN;
vector<int> neg;
int val = m;
for(int i = 0; i < m; ++i) {
for(int j = 0; j < a[i]; ++j) neg.push_back(val);
--val;
}
vector<int> pos;
val = 1;
for(int i = m + 1; i < 2 * m + 1; ++i) {
for(int j = 0; j < a[i]; ++j) pos.push_back(val);
++val;
}
vector<int> pp = calc(pos);
vector<int> ng = calc(neg);
if(l < 0) {
swap(pp, ng);
l = -l;
}
for(int sum = l; sum < (int)pp.size(); ++sum) {
if(sum - l >= (int)ng.size() || pp[sum] == INT_MIN || ng[sum - l] == INT_MIN) continue;
ans = max(ans, pp[sum] + ng[sum - l] + a[m]);
}
if(ans == INT_MIN) cout << "impossible\n";
else cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Runtime error |
214 ms |
1444 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Runtime error |
214 ms |
1444 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
550 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
550 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
550 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Runtime error |
214 ms |
1444 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
550 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Runtime error |
214 ms |
1444 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
550 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Runtime error |
214 ms |
1444 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |