#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100;
int M;
ll L;
vector<int> pos(maxn+5), neg(maxn+5);
void solve(){
cin >> M >> L;
for(int i = 1; i <= M; i++)
cin >> neg[M-i+1];
ll ans;
cin >> ans;
for(int i = 1; i <= M; i++)
cin >> pos[i];
int maxn3 = (maxn*maxn+1)/2*maxn;
vector<ll> knapsack1(maxn3+5, -1e18), knapsack2(maxn3+5, -1e18);
set<int> S;
knapsack1[0] = knapsack2[0] = 0;
S.insert(0);
for(int i = 1; i <= M; i++){
set<int> news;
for(auto it = S.rbegin(); it != S.rend(); it++){
int val = *it;
for(int use = 1; use <= max(pos[i], neg[i]); use++){
if(val+use*i <= maxn3 && use <= pos[i] && knapsack1[val] != -1e18){
knapsack1[val+use*i] = max(knapsack1[val+use*i], knapsack1[val]+use);
news.insert(val+use*i);
}
if(val+use*i <= maxn3 && use <= neg[i] && knapsack2[val] != -1e18){
knapsack2[val+use*i] = max(knapsack2[val+use*i], knapsack2[val]+use);
news.insert(val+use*i);
}
}
}
for(int i : news)
S.insert(i);
}
ll add = -1e18;
for(int i = 0; i <= maxn3; i++){
ll need = L-i;
if(need > 0){
continue;
}else if(need == 0){
add = max(add, knapsack1[i]);
}else if(-need >= maxn3 || knapsack2[-need] == -1e18 || knapsack1[i] == -1e18){
continue;
}else{
add = max(add, knapsack1[i] + knapsack2[-need]);
}
}
if(add == -1e18){
cout << "impossible\n";
}else{
cout << ans+add;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
// cin >> tt;
while(tt--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8112 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8148 KB |
Output is correct |
5 |
Correct |
1589 ms |
11288 KB |
Output is correct |
6 |
Correct |
1747 ms |
11452 KB |
Output is correct |
7 |
Correct |
345 ms |
9888 KB |
Output is correct |
8 |
Correct |
1729 ms |
11128 KB |
Output is correct |
9 |
Execution timed out |
5067 ms |
13420 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8112 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8148 KB |
Output is correct |
5 |
Correct |
1589 ms |
11288 KB |
Output is correct |
6 |
Correct |
1747 ms |
11452 KB |
Output is correct |
7 |
Correct |
345 ms |
9888 KB |
Output is correct |
8 |
Correct |
1729 ms |
11128 KB |
Output is correct |
9 |
Execution timed out |
5067 ms |
13420 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
587 ms |
32096 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
587 ms |
32096 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
587 ms |
32096 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8112 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8148 KB |
Output is correct |
5 |
Correct |
1589 ms |
11288 KB |
Output is correct |
6 |
Correct |
1747 ms |
11452 KB |
Output is correct |
7 |
Correct |
345 ms |
9888 KB |
Output is correct |
8 |
Correct |
1729 ms |
11128 KB |
Output is correct |
9 |
Execution timed out |
5067 ms |
13420 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
587 ms |
32096 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8112 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8148 KB |
Output is correct |
5 |
Correct |
1589 ms |
11288 KB |
Output is correct |
6 |
Correct |
1747 ms |
11452 KB |
Output is correct |
7 |
Correct |
345 ms |
9888 KB |
Output is correct |
8 |
Correct |
1729 ms |
11128 KB |
Output is correct |
9 |
Execution timed out |
5067 ms |
13420 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
587 ms |
32096 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8112 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8148 KB |
Output is correct |
5 |
Correct |
1589 ms |
11288 KB |
Output is correct |
6 |
Correct |
1747 ms |
11452 KB |
Output is correct |
7 |
Correct |
345 ms |
9888 KB |
Output is correct |
8 |
Correct |
1729 ms |
11128 KB |
Output is correct |
9 |
Execution timed out |
5067 ms |
13420 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |