-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPARTY.cpp
More file actions
44 lines (42 loc) · 878 Bytes
/
PARTY.cpp
File metadata and controls
44 lines (42 loc) · 878 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
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,b,fun,bud;
while(1)
{
scanf("%d%d",&b,&n);
if(b==0&&n==0)
break;
int fun[n+1],bud[n+1];
for(int i=0;i<n;i++)
{
scanf("%d%d",&bud[i],&fun[i]);
}
int kp[n+1][b+1],cost=0;
for(int i=0;i<=n;i++)
{
for(int j=0;j<=b;j++)
{
if(i==0||j==0)
kp[i][j]=0;
else if(bud[i-1]<=j)
{
kp[i][j]=max(kp[i-1][j],fun[i-1]+kp[i-1][j-bud[i-1]]);
}
else
kp[i][j]=kp[i-1][j];
}
}
int ma=kp[n][b];
cost=b;
while(cost)
{
if(kp[n][cost]<ma)
break;
cost--;
}
cout<<cost+1<<" "<<kp[n][b]<<endl;
}
// your code goes here
return 0;
}