-
Notifications
You must be signed in to change notification settings - Fork 0
/
party.cpp
38 lines (36 loc) · 818 Bytes
/
party.cpp
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
#include<bits/stdc++.h>
using namespace std;
int arr[101][501];
int main()
{
int party_max,no_party;
scanf("%d %d",&party_max,&no_party);
while(party_max!=0){
for(int i=0;i<=party_max;i++)
{
for(int j=0;j<=no_party;j++)
{arr[j][i]=0;}
}
int coun=0,a,b;
for(int k=0;k<no_party;k++)
{
scanf("%d %d",&a,&b);
coun++;
for(int i=1;i<=party_max;i++)
{
if( i < a){arr[coun][i]=arr[coun-1][i];}
else {
arr[coun][i]=max(arr[coun-1][i],arr[coun-1][i-a]+b);
}
}
}
int last= arr[no_party][party_max];
int j=party_max;
while(arr[no_party][j]==last)
{
j--;
}
printf("%d %d\n",j+1,arr[no_party][j+1]);
scanf("%d %d",&party_max,&no_party);
}
}