Cod sursa(job #1807590)

Utilizator longzsoltLongauer Zsolt longzsolt Data 16 noiembrie 2016 18:50:38
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<fstream>
#include <iostream>

using namespace std;

int main()
{
	ifstream in("loto.in");
	int n, s;
	bool nb[101] = { false };
	in >> n >> s;
	int am = 0;
	int sor = s;
	for (int i = 0; i < n; i++)
	{
		int a;
		in >> a;
		if (am < a) am = a;
		nb[a] = true;
	}
	int v[6] = { 0 };
	int fs = 6;
	int ar = am;
	int fsum = 0;
	for (int i = 0; i < 6; i++)
	{
		while (v[i] == 0)
		{
			if (s / am >= fs)
			{
				v[i] = am;
				s -= am;
				fs--;
				fsum += am;
				am = ar;
			}
			else
			{
				am--;
				while (!nb[am]) am--;
			}
		}
	}
	ofstream out("loto.out");
	if (fsum != sor) out << -1;
	else
	{
		for (int i = 0; i < 6; i++)
		{
			out << v[i] << " ";
		}
	}
	return 0;
}