-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaitui.cpp
More file actions
39 lines (38 loc) · 865 Bytes
/
caitui.cpp
File metadata and controls
39 lines (38 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// created by:DungTD
//
#include <bits/stdc++.h>
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define base int (1e9+7)
#define ll long long
using namespace std;
int l[1005][1005] = {0};
void solve(){
int n, v;
cin >> n >> v;
int a[1005] = {0};
int c[1005] = {0};
for (int i=0; i<=1000; i++) {
for (int j=0; j<=1000; j++) l[i][j] = 0;
}
for (int i=1; i<=n; i++) cin >> a[i];
for (int i=1; i<=n; i++) cin >> c[i];
for (int i=1; i<=n; i++) {
for (int j=1; j<=v; j++) {
if (a[i] <= j) {
l[i][j] = max(l[i-1][j-a[i]] + c[i], l[i-1][j]);
}
else l[i][j] = l[i-1][j];
}
}
cout << l[n][v] << endl;
}
int main(){
faster();
int t;
cin >> t;
while (t--)
solve();
return 0;
}