Pagini recente » Cod sursa (job #2467976) | Cod sursa (job #2784491) | Cod sursa (job #1886043) | Cod sursa (job #1254590) | Cod sursa (job #2121540)
#include <fstream>
using namespace std;
ifstream cin ("ghiozdan.in");
ofstream cout ("ghiozdan.out");
int fv [201];
int last [75001];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n , G;
cin>>n>>G;
for (int i=1; i<=n; i++){
int nr;
cin>>nr;
fv[nr]++;
}
last[0] = -1;
for (int i=200; i>=1; i--){
for (int j=G; j>=0; j--){
if (!last[j]){
continue;
}
for (int k=1; k<=fv[i]; k++){
int now = j + i*k;
if (now > G){
break;
}
if (last[now]){
break;
}
last[now] = i;
}
}
}
int now = 0;
for (int i=G; i>=0; i--){
if (last[i]){
now = i;
break;
}
}
int old = now;
int cont = 0;
while (last[now] != -1){
cont++;
now = now - last[now];
}
cout<<old<<" "<<cont<<'\n';
while (last[old] != -1){
cout<<last[old]<<'\n';
old = old - last[old];
}
return 0;
}