Cod sursa(job #720205)

Utilizator mottyMatei-Dan Epure motty Data 22 martie 2012 14:08:32
Problema Zebughil Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <fstream>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

ifstream in("zebughil.in");
ofstream out("zebughil.out");

const int N = 18;

long long v[N];
long long c[N];
int noCam;

inline bool cmp(int a, int b) {
	return (a > b);
}

int main() {
	int t = 3;
	while (t--) {
		int n;
		long long g;
		in >> n >> g;
		
		for (int i = 1; i <= n; ++i)
			in >> v[i];
		sort(v+1, v+n+1, cmp);
		
		memset(c, 0, sizeof(c));
		noCam = 0;
		
		bool smecherie;
		
		for (int i = 1; i <= n; ++i) {
			smecherie = false;
			for (int j = 1; j <= noCam; ++j) {
				if (c[j] + v[i] <= g) {
					c[j] += v[i];
					smecherie = true;
					break;
				}
			}
			
			if (!smecherie) {
				c[++noCam] = v[i];
			}
		}
		
		out << noCam << "\n";
	}
	
	return 0;
}