Cod sursa(job #130776)
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
int n, g, s[20], v[20], ok, contor;
void citire()
{
scanf("%d %d", &n, &g);
for (int i = 0; i < n; i++) scanf ("%d",v + i);
}
int cmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
int main()
{
freopen("zebughil.in","r",stdin);
freopen("zebughil.out","w",stdout);
int z, i, j;
for (z = 1; z <= 3; z++)
{
citire();
qsort(v,n,sizeof(int),cmp);
memset(s,0,sizeof(s));
contor = 1;
for (i = n - 1; i >= 0; i--)
{
for (j = 1; j <= contor; j++)
{
if (g - s[j] >= v[i])
{
s[j] += v[i];
break;
}
}
if (j > contor) s[++contor] = v[i];
}
printf("%d\n",contor);
}
return 0;
}