Pagini recente » Cod sursa (job #1946249) | Cod sursa (job #1402387) | Cod sursa (job #1134148) | Cod sursa (job #1554078) | Cod sursa (job #2001468)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");
int f[210];
int last[75010];
int dp[75010];
int main()
{
int n, G;
fin >> n >> G;
for(int i=1; i<=n; i++)
{
int x;
fin >> x;
f[x]++;
}
dp[0]=1;
for(int i=200;i>0;i--)
if(f[i])
for(int j=G-i;j>=0;j--)
if(dp[j])
for(int k=1; k<=f[i]; k++)
{
if(j+k*i>G || dp[j+k*i]) break;
dp[j+k*i]=dp[j]+k;
last[j+k*i]=i;
}
for(int i=G;i>0;i--)
if(dp[i])
{
fout << i << ' ' << dp[i]-1 << '\n';
while(i)
{
fout << last[i] << '\n';
i -= last[i];
}
return 0;
}
return 0;
}