Cod sursa(job #1379686)

Utilizator RazecBotez Cezar Razec Data 6 martie 2015 18:58:48
Problema Zebughil Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("zebughil.in");
ofstream g("zebughil.out");
int n,x[20],y[20],gmax,i,j,k;
int main()
{
    for(int cnt=3;cnt;cnt--)
    {
        f>>n>>gmax;
        for(i=1;i<=n;i++)
        {
            f>>x[i];
            y[i]=gmax;
        }
        y[0]=gmax+1;
        sort(x+1,x+n+1);
        for(i=n;i>=1;i--)
        {
            j=0;
            for(k=1;k<=n;k++)
                if(y[k]>=x[i]&&y[k]<y[j])
                        j=k;
            y[j]-=x[i];
        }
        j=0;
        for(i=1;i<=n;i++)
            if(y[i]<gmax)
                j++;
        g<<j<<'\n';
    }
    return 0;
}