-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulsum.cpp
More file actions
34 lines (31 loc) · 743 Bytes
/
mulsum.cpp
File metadata and controls
34 lines (31 loc) · 743 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
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int s, n;
int a[100], m[100];
int dp[100][1005];
int main(){
cin >> s >> n;
for(int i=0; i<n; i++) cin >> a[i] >> m[i];
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for(int i=0; i<n; i++){
for(int j=0; j<=s; j++){
if(dp[i][j]>=0){
dp[i+1][j] = m[i];
}else if(j >= a[i] && dp[i+1][j-a[i]] >= 0){
dp[i+1][j] = max(dp[i][j], dp[i+1][j-a[i]]-1);
}
}
}
for(int i=0; i<=n; i++){
for(int j=0; j<=s; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}
if(dp[n][s] >= 0) cout << "yes";
else cout << "no";
return 0;
}