Cod sursa(job #1594944)

Utilizator Cudrici_CarinaCudrici Carina Cudrici_Carina Data 9 februarie 2016 20:28:29
Problema Ghiozdan Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
using namespace std;
ifstream fi("ghiozdan.in");
ofstream fo("ghiozdan.out");
int fr[201],x,poz,k,i,j,nr,n,g,c[75001];
int main()
{fi>>n>>g;
for (i=1;i<=n;i++) {fi>>x;fr[x]++;}
c[0]=1;
for (i=200;i>=1;i--)  if (fr[i])
for (j=g; j>=0; j--)  if (c[j])
for(k=1; k<=fr[i] and j+k*i<=g  ;k++)
    {   poz=j+k*i;
        if (c[poz]) break ;
        c[poz]=i;
    }

for (i=g;c[i]==0;i--);           fo<<i<<" ";
for (j=i; j!=0;j-=c[j]) nr++;    fo<<nr<<'\n';
for (j=i; j!=0;j-=c[j]) fo<<c[j]<<'\n';
    return 0;
}