Pagini recente » Cod sursa (job #2941223) | Cod sursa (job #3002951) | Cod sursa (job #939687) | Cod sursa (job #3278956) | Cod sursa (job #3221786)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");
int n,g;
const int smax = 75000;
const int INF = 1e9;
int d[smax + 5];
int t[smax + 5];
int v[20005];
void afis(int ind)
{
fout<<ind<<' ';
if(ind){
afis(t[ind]);
//fout<<ind-t[ind]<<'\n';
}
}
int main()
{
for(int i=0;i<=smax;i++)
d[i]=INF;
fin>>n>>g;
d[0]=0;
for(int i=1;i<=n;i++)
{
fin>>v[i];
for(int j = g-v[i];j>=0;j--)
if(d[j]!=INF)
d[j+v[i]]=min(d[j+v[i]],d[j] + 1),t[j+v[i]]=j;
}
int ind = 0 ;
for(int j = smax;j>=0;j--)
if(d[j]!=INF){
ind = j;break;}
fout<<ind<<' '<<d[ind]<<'\n';
}