Pagini recente » Cod sursa (job #2623643) | Cod sursa (job #18381) | Cod sursa (job #1816583) | Cod sursa (job #1351381) | Cod sursa (job #2151573)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("ghiozdan.in");
ofstream out("ghiozdan.out");
const int NMAX = 75000;
const int VMAX = 200;
const int DIM = 2 * 1e6;
int n, g, res;
int ap[1 + VMAX];
int dp[1 + NMAX];
int sol[1 + NMAX];
int pos1;
char buff[DIM];
void read(int &x) {
x = 0;
while(!isdigit(buff[pos1])) {
if(++pos1 == DIM) {
in.read(buff, DIM);
pos1 = 0;
}
}
while(isdigit(buff[pos1])) {
x = x * 10 + (buff[pos1] - '0');
if(++pos1 == DIM) {
in.read(buff, DIM);
pos1 = 0;
}
}
}
int main()
{
//in >> n >> g;
read(n);
read(g);
for(int i = 1; i <= n; i++) {
int x;
//in >> x;
read(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;
}
}
}
}
}
out << res << ' ' << dp[res] - 1 << '\n';
while(res != 0) {
out << sol[res] << '\n';
res -= sol[res];
}
in.close();
out.close();
return 0;
}