Pagini recente » Cod sursa (job #874444) | Cod sursa (job #1954938) | Cod sursa (job #1434898) | Cod sursa (job #1501833) | Cod sursa (job #1964520)
#include <fstream>
#define VAL 75005
using namespace std;
ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");
int N, G, i, j;
int dp[VAL], nr;
int last[VAL], mx;
int main()
{
fin >> N >> G;
for (i=1; i<=N; i++)
{
fin >> nr;
for (j=G-nr; j>=0; j--)
{
if (dp[j]!=0)
{
if (dp[j+nr]==0)
{
dp[j+nr]=dp[j]+1;
last[j+nr]=nr;
mx=max(mx, j+nr);
}
else
{
if (dp[j+nr]>dp[j]+1)
{
dp[j+nr]=dp[j]+1;
last[j+nr]=nr;
mx=max(mx, j+nr);
}
}
}
if (j==0)
{
mx=max(mx, nr);
dp[nr]=1;
last[nr]=nr;
}
}
}
fout << mx << " " << dp[mx] << '\n';
while (mx!=0)
{
fout << last[mx] << '\n';
mx-=last[mx];
}
fin.close();
fout.close();
return 0;
}