Cod sursa(job #2245225)

Utilizator Vertex10Alexandru Pokharel Vertex10 Data 24 septembrie 2018 21:09:43
Problema Sate2 Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.95 kb
#define _CRET_SECURE_NO_WARNINGS

#include<cstdio>
#include<fstream>
#include<algorithm>

using namespace std;
ifstream f("sate2.in");
ofstream g("sate2.out");




int main()
{
	int n, t, k, m, a[3001], c, kaux = 0, s = 0;
	f >> t;
	while (t)
	{
		f >> n >> m >> k;
		c = m / k;
		if (m % k)
		{
			g << "NU\n";
			--t;
			continue;
		}


		for (int i = 0; i < n; ++i)
			f >> a[i];
		sort(a, a + n);

		if (a[n - 1] > c || a[n - 2] > c)
		{
			g << "NU\n";
			--t;
			continue;
		}

		kaux = 0; //cate sate am format pana in prezent
		while (kaux < k)
		{
			s = 0;
			for (int i = n-1; i >= 0 && s < c; --i)
			{
				if (a[i] && s + a[i] <= c)
				{
					s += a[i];
					a[i] = 0;
					continue;
				}

				if (i == 0 && s < c) //daca am parc tot vect si tot nu am putut construi suma
				{
					g << "NU\n";
					goto afara;
				}
			}
			++kaux;

		}

		
		g << "DA\n";
	
		afara:
		--t;
	}
	


}