#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*maxn;
vector<ll> knapsack1(maxn3+5, -1e18);
knapsack1[0] = 0;
for(int i = 1; i <= M; i++){
for(int make = maxn3; make >= 0; make--){
for(int use = 1; use <= pos[i] && use*1ll*i <= maxn3; use++){
if(use*i <= make)
knapsack1[make] = max(knapsack1[make], knapsack1[make-use*i]+use);
}
}
}
vector<ll> knapsack2(maxn3+5, -1e18);
knapsack2[0] = 0;
for(int i = 1; i <= M; i++){
for(int make = maxn3; make >= 0; make--){
for(int use = 1; use <= neg[i] && use*1ll*i <= maxn3; use++){
if(use*i <= make)
knapsack2[make] = max(knapsack2[make], knapsack2[make-use*i]+use);
}
}
}
ll add = 0;
for(int i = 0; i <= maxn3; i++){
ll need = L-i;
if(need > 0)
continue;
if(need == 0)
add = max(add, knapsack1[i]);
else
add = max(add, knapsack1[i] + knapsack2[-need]);
}
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 |
32 ms |
15960 KB |
Output is correct |
2 |
Incorrect |
26 ms |
15948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
15960 KB |
Output is correct |
2 |
Incorrect |
26 ms |
15948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
15948 KB |
Output is correct |
2 |
Execution timed out |
5079 ms |
8128 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
15948 KB |
Output is correct |
2 |
Execution timed out |
5079 ms |
8128 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
15948 KB |
Output is correct |
2 |
Execution timed out |
5079 ms |
8128 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
15960 KB |
Output is correct |
2 |
Incorrect |
26 ms |
15948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
15948 KB |
Output is correct |
2 |
Execution timed out |
5079 ms |
8128 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
15960 KB |
Output is correct |
2 |
Incorrect |
26 ms |
15948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
15948 KB |
Output is correct |
2 |
Execution timed out |
5079 ms |
8128 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
15960 KB |
Output is correct |
2 |
Incorrect |
26 ms |
15948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |