Cod sursa(job #2398381)
Utilizator | Fabian Anghel fabian_anghel | Data | 5 aprilie 2019 13:30:37 |
---|---|---|---|
Problema | Zebughil | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.83 kb |
#include <fstream>
#include <algorithm>
using namespace std;
int N,v[18],G,fr[18],nr;
ifstream f ("zebughil.in");
ofstream g ("zebughil.out");
bool comp(int A,int B)
{
return A>B;
}
int main()
{
for(int i=1;i<=3;i++)
{
f>>N>>G;
nr=0;
for(int i=1;i<=N;i++)
{
f>>v[i];
fr[i]=0;
}
sort(v+1,v+N+1,comp);
for(int i=1;i<=N;i++)
if(fr[i]==0)
{
nr++;
fr[i]=1;
int S=v[i];
for(int j=i+1;j<=N;j++)
if(fr[j]==0 && S+v[j]<=G)
{
fr[j]=1;
S+=v[j];
}
}
g<<nr<<'\n';
}
f.close();
g.close();
return 0;
}