Pagini recente » Cod sursa (job #1948098) | Cod sursa (job #2397445) | Cod sursa (job #1133945) | Cod sursa (job #760514) | Cod sursa (job #2407568)
#include<bits/stdc++.h>
using namespace std;
ifstream f("ghiozdan.in");
ofstream g("ghiozdan.out");
int n, W;
int fv[210];
int last[75100];
int dp[75100] = {1}, ap[75100];
int main()
{
f >> n >> W;
for(int i=1, x; i<=n; i++)
f >> x, fv[x]++;
for(int i=200; i; i--)
{
if(!fv[i])
continue;
for(int j=W; j>=0; j--)
if(dp[j])
for(int d=1; d<=fv[i] && j+d*i <= W && !dp[j + d*i]; d++)
dp[j+d*i] = dp[j] + d, ap[j+d*i] = i;
}
int j = W;
while (j && !dp[j])
j--;
g << j << " " << dp[j]-1 << '\n';
while(j > 0)
{
g << ap[j] << '\n';
j -= ap[j];
}
return 0;
}