-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhelp_heroes.cpp
More file actions
60 lines (52 loc) · 1.31 KB
/
help_heroes.cpp
File metadata and controls
60 lines (52 loc) · 1.31 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// link :: https://www.spoj.com/problems/DBALLZ/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define boost1 ios::sync_with_stdio(0)
#define boost2 cin.tie(0)
#define size1 200005
#define mod 1000000007
#define vll vector < ll >
#define vpll vector < pair < ll ,ll> >
#define pii pair < int,int >
#define pll pair < ll,ll >
#define fi first
#define se second
#define pb(x) push_back(x)
#define endl "\n"
#define mem1(x) memset(x,-1,sizeof x)
#define mem(x) memset(x,0,sizeof x)
#define mem63(x) memset(x,63,sizeof x)
int dp[(int)1e6 + 5],val[(int)1e3+5],W[(int)1e6 + 5];
int main()
{
boost1;
boost2;
int m,i,j,t,x,y,w,n;
cin>>t;
while(t--){
cin>>w>>n;
for(i=0;i<n;i++){
cin>>W[i];
}
for(i=0;i<n;i++){
cin>>val[i];
}
mem(dp);
for(i=0;i<=w;i++){
for(j=0;j<n;j++){
if(W[j] <= i){
dp[i] = max(dp[i],dp[i-W[j]] + val[j]);
}
}
}
// for(i=0;i<100;i++){
// cout<<dp[i]<<" ";
// }
// cout<<endl;
cout<<*max_element(dp,dp+w+1)<<endl;
}
return 0;
}