Pagini recente » Cod sursa (job #2228573) | Cod sursa (job #1924492) | Cod sursa (job #2522613) | Cod sursa (job #925021) | Cod sursa (job #957613)
Cod sursa(job #957613)
#include <fstream>
#include <algorithm>
#include <string.h>
using namespace std;
ifstream f("zebughil.in");
ofstream g("zebughil.out");
long long n,a[20];
long long G;
bool v[20];
void find()
{
long long i=n-1,j=n-1,counter=0;
long long s=a[i];
for(i=n-1;i>=0;i--)
{
if(v[i]==0)
counter++;
else
continue;
v[i]=1;
s=a[i];
j=i-1;
while(j>=0)
{
if(v[j]==0)
{
if(a[j]+s<=G)
{
v[j]=1;
s+=a[j];
}
}
j--;
}
}
g<<counter<<"\n";
}
void read_and_browse()
{
int i,j;
for(i=0;i<3;i++)
{
f>>n;
f>>G;
for(j=0;j<n;j++)
f>>a[j];
sort(a,a+n);
memset(v,0,sizeof(v));
find();
}
}
int main()
{
read_and_browse();
return 0;
}