Pagini recente » Cod sursa (job #2683133) | Cod sursa (job #619968) | Cod sursa (job #24917) | Cod sursa (job #929438) | Cod sursa (job #2198237)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");
int f[210];
int last[75010];
int dp[75010];
int main()
{
int n, G;
fin >> n >> G;
for(int i=1; i<=n; i++)
{
int x;
fin >> x;
f[x]++;
}
dp[0]=1;
for(int i=200;i>0;i--)
if(f[i])
for(int j=G-i;j>=0;j--)
if(dp[j])
for(int k=1; k<=f[i]; k++)
{
if(j+k*i>G || dp[j+k*i]) break;
dp[j+k*i]=dp[j]+k;
last[j+k*i]=i;
}
for(int i=G;i>0;i--)
if(dp[i])
{
fout << i << ' ' << dp[i]-1 << '\n';
while(i)
{
//fout << last[i] << '\n';
i -= last[i];
}
return 0;
}
return 0;
}