Pagini recente » Cod sursa (job #2187426) | Cod sursa (job #386878) | Cod sursa (job #1487706) | Cod sursa (job #1447806) | Cod sursa (job #1790822)
#include <bits/stdc++.h>
#define INF 200000000
using namespace std;
ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");
int D[135010], N, G, fr[250], x, T[135010];
int solutionG, nr;
inline void way(int x)
{
if(T[x] == 0)
{
return;
}
fout << T[x] << '\n';
if(T[x] > 0)
{
way(x - T[x]);
}
}
int main()
{
fin >> N >> G;
for(int i = 1; i <= G; i ++)
{
D[i] = INF;
}
for(int i = 1; i <= N; i ++)
{
fin >> x;
fr[x] ++;
}
for(int i = 200; i >= 1; i --)
{
if(fr[i] == 0)
{
continue;
}
for(int j = G; j >= 0; j --)
{
if(D[j] != INF)
{
for(int k = 1; k <= fr[i] && j + i * k <= G; k ++)
{
if(D[j + i * k] == INF)
{
D[j + i * k] = D[j] + k;
T[j + i * k] = i;
solutionG = max(j + i * k, solutionG);
}
else
{
break;
}
}
}
}
}
fout << solutionG << " " << D[solutionG] << '\n';
way(solutionG);
return 0;
}