Pagini recente » Cod sursa (job #982314) | Cod sursa (job #1252917) | Cod sursa (job #874038) | Cod sursa (job #2285779) | Cod sursa (job #1111501)
#include <fstream>
#include <iostream>
using namespace std;
long a[20001],Gmax,v[20001],g[202],i,n,j,s,k,x;
int main()
{
ifstream f( "ghiozdan.in");
ofstream h( "ghiozdan.out");
f>>n>>Gmax;
for(i=1;i<=n;i++)
{f>>x;g[x]++;
}
for (i=201;i>=1;i--)
if(g[i]!=0)
{for(k=1;k<=g[i];k++)
for(j=Gmax;j>=i;j--)
if(i+a[j-i]>a[j])
{a[j]=i+a[j-i];
v[j]=1+v[j-i];}
else
if (i+a[j-i]==a[j])
if(v[j]>1+v[j-i])
v[j]=1+v[j-i];
/*cout<<"-------------"<<g[i]<<endl;
for(k=1;k<=Gmax;k++)
cout<<k<<" ";
cout<<endl;
for(k=1;k<=Gmax;k++)
cout<<a[k]<<" ";
cout<<endl;
for(k=1;k<=Gmax;k++)
cout<<v[k]<<" ";
cout<<endl;*/
}
h<<a[Gmax]<<" "<<v[Gmax];
}