Cod sursa(job #2439099)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 14 iulie 2019 23:19:04
Problema Zebughil Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
	ifstream cin("zebughil.in");
	ofstream cout("zebughil.out");

	for (int i = 0; i < 3; ++i) {
		ll n, g;
		cin >> n >> g;

		vector < ll > v(n);
		for (int i = 0; i < n; ++i) {
			cin >> v[i];
		}

		sort(v.begin(), v.end());
		multiset < int > Set;
		for (int i = n - 1; i >= 0; --i) {
			auto it = Set.lower_bound(v[i]);
			if (it == Set.end()) {
				Set.insert(g - v[i]);
			} else {
				Set.insert(*it - v[i]);
				Set.erase(Set.find(*it));
			}
		}

		cout << Set.size() << endl;
	}
	return 0;
}