#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 100500;
const int LIM = 100 * 100 * 101 / 2 + 1;
vector<int> knapsack(vector<int> a){
vector<int> dp(LIM, -1e9);
dp[0] = 0;
for (int x : a) {
for (int i = LIM - 1; i >= x; i--) {
dp[i] = max(dp[i], dp[i - x] + 1);
}
}
return dp;
}
void solve(){
int m; ll L;
cin >> m >> L;
vector<int> pos, neg;
for (int i = -m; i <= m; i++){
int x;
cin >> x;
while (x--){
if (i >= 0){
pos.push_back(i);
} else {
neg.push_back(-i);
}
}
}
vector<int> dp1 = knapsack(pos);
vector<int> dp2 = knapsack(neg);
int ans = -1e9;
for (int x = L; x < LIM; x++){
int y = x - L;
ans = max(ans, dp1[x] + dp2[y]);
}
if (ans < 0) {
cout << "impossible" << endl;
} else {
cout << ans << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
29 ms |
4172 KB |
Output is correct |
5 |
Correct |
1086 ms |
4232 KB |
Output is correct |
6 |
Correct |
1151 ms |
4296 KB |
Output is correct |
7 |
Incorrect |
479 ms |
4280 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
29 ms |
4172 KB |
Output is correct |
5 |
Correct |
1086 ms |
4232 KB |
Output is correct |
6 |
Correct |
1151 ms |
4296 KB |
Output is correct |
7 |
Incorrect |
479 ms |
4280 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4208 KB |
Output is correct |
2 |
Runtime error |
554 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4208 KB |
Output is correct |
2 |
Runtime error |
554 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4208 KB |
Output is correct |
2 |
Runtime error |
554 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
29 ms |
4172 KB |
Output is correct |
5 |
Correct |
1086 ms |
4232 KB |
Output is correct |
6 |
Correct |
1151 ms |
4296 KB |
Output is correct |
7 |
Incorrect |
479 ms |
4280 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4208 KB |
Output is correct |
2 |
Runtime error |
554 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
29 ms |
4172 KB |
Output is correct |
5 |
Correct |
1086 ms |
4232 KB |
Output is correct |
6 |
Correct |
1151 ms |
4296 KB |
Output is correct |
7 |
Incorrect |
479 ms |
4280 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4208 KB |
Output is correct |
2 |
Runtime error |
554 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4180 KB |
Output is correct |
4 |
Correct |
29 ms |
4172 KB |
Output is correct |
5 |
Correct |
1086 ms |
4232 KB |
Output is correct |
6 |
Correct |
1151 ms |
4296 KB |
Output is correct |
7 |
Incorrect |
479 ms |
4280 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |