Mai intai trebuie sa te autentifici.

Cod sursa(job #2479746)

Utilizator invoIlioi Alexandru invo Data 24 octombrie 2019 14:24:06
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include<fstream>
#include<vector>
#include<algorithm>

ifstream f("loto.in");
ofstream g("loto.out");

using namespace std;
#define MAX 101

bool myfunction(int i, int j) { return (i > j); }

int main()
{
	int n, s,b;
	vector<int> a;
	vector<int> sol;
	int temp = 6;
	int val;
	bool found = false;
	f >> n >> s;
	for (int i = 0; i < n; ++i)
	{
		f >> b;
		a.push_back(b);
	}
	sort(a.begin(), a.end(), myfunction);
	while (sol.size() < 6)
	{
		found = false;
		for (int i = 0; i < n; ++i)
		{
			val = a[i] * temp;
			if (val <= s)
			{
				found = true;
				sol.push_back(a[i]);
				s -= a[i];
				break;
			}
		}
		if (!found)
		{
			g << -1 << endl;
			return 0;
		}
		temp--;
	}
	if (s != 0)
	{
		g << -1 << endl;
	}
	else
	{
		for (int i = 0; i < 6; ++i)
		{
			g << sol[i] << ' ';
		}
		g << endl;
	}
}