Cod sursa(job #1033095)

Utilizator harababurelPuscas Sergiu harababurel Data 16 noiembrie 2013 14:21:37
Problema Grupuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#define nmax 100005
using namespace std;

int n, k, v[nmax], sol = 0;

int main() {
	ifstream f("grupuri.in");
	ofstream g("grupuri.out");
	
	f>>k>>n;
	for(int i=1; i<=n; i++) f>>v[i];
	sort(v+1, v+n+1);

	int lo, hi = n;
	for(lo=1; lo<hi; lo++) {
		while(hi > 1 && v[hi] >= k) hi--;

		if(v[hi] < k) {
			v[hi] += v[lo];
			v[lo] = 0;
		}
	}

	for(int i=1; i<=n; i++) if(v[i] >= k) sol++;

	g<<sol<<"\n";
	return 0;
}