Pagini recente » Cod sursa (job #913681) | Cod sursa (job #3184185) | Cod sursa (job #1249163) | Cod sursa (job #2609013) | Cod sursa (job #2515153)
#include <iostream>
#include<cstdio>
#include<fstream>
using namespace std;
ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");
const int N=205;
const int NMAX=75005;
int fr[N],dp[NMAX];
struct ajutorsol{
int val,sz;
};
ajutorsol last[NMAX];
int main()
{
ios::sync_with_stdio (false);
fin.tie (0);
fout.tie (0);
int n,g;
fin>>n>>g;
for(int i=1;i<=n;i++){
int a;
fin>>a;
fr[a]++;
}
for(int i=200;i>0;i--){
if(fr[i]){
for(int j=g;j>=0;j--){
if(dp[j] || j==0){
for(int k=1;k<=fr[i] && k*i+j<=g;k++){
if(dp[j+k*i]==0){
last[j+k*i]={i,k};
dp[j+k*i]=dp[j]+k;
}
}
}
}
}
}
int gmax=g;
while(dp[gmax]==0 && gmax>0){
gmax--;
}
fout<<gmax<<" "<<dp[gmax]<<"\n";
while(gmax){
int sz=last[gmax].sz;
while(sz--){
fout<<last[gmax].val<<"\n";
}
gmax=gmax-last[gmax].val*last[gmax].sz;
}
return 0;
}