Pagini recente » Cod sursa (job #1789946) | Cod sursa (job #991092) | Cod sursa (job #2010747) | Cod sursa (job #1963040) | Cod sursa (job #2271243)
#include <fstream>
using namespace std;
ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");
const int NMAX = 75000;
const int VMAX = 200;
int n, g, res;
int ap[1 + VMAX];
int dp[1 + NMAX];
int sol[1 + NMAX];
int main()
{
fin>>n>>g;
for(int i = 1; i <= n; i++) {
int x;
fin >> x;
ap[x]++;
}
dp[0] = 1;
for(int i = VMAX; i >= 1; i--) {
if(0 < ap[i]) {
for(int k = g - i; k >= 0; k--) {
if(dp[k] == 0)
continue;
for(int j = 1; j <= ap[i]; j++) {
int p = i * j + k;
if(p <= g && dp[p] == 0) {
dp[p] = dp[k] + j;
sol[p] = i;
res = max(res, p);
} else {
break;
}
}
}
}
}
fout << res << ' ' << dp[res] - 1 << '\n';
while(res != 0) {
fout << sol[res] << '\n';
res -= sol[res];
}
fin.close();
fout.close();
return 0;
}