Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Istoria paginii runda/numere_reale/clasament | Cod sursa (job #2021034)
#include <iostream>
#include <fstream>
using namespace std;
ifstream si("ghiozdan.in");
ofstream so("ghiozdan.out");
int fr[205],c[75005];
int main()
{
int n,g,x;
si>>n>>g;
for(int i=1;i<=n;i++)
{
si>>x;
fr[x]++;
}
c[0]=1;
int i;
for(i=200;i>=1;i--)
if(fr[i])
for(int j=g;j>=0;j--)
if(c[j])
for(int k=1;k<=fr[i]&&j+k*i<=g;k++)
{
int poz=j+k*i;
if(c[poz])
break;
c[poz]=i;
}
for(i=g;c[i]==0;i--);
so<<i<<" ";
int nr=0;
for(int j=i;j!=0;j-=c[j])
nr++;
so<<nr<<'\n';
for(int j=i;j!=0;j-=c[j])
so<<c[j]<<'\n';
return 0;
}