Cod sursa(job #2524491)

Utilizator AlexNeaguAlexandru AlexNeagu Data 15 ianuarie 2020 20:06:27
Problema Loto Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 666013;
const int N = 105;
int v[N];
ifstream in("loto.in");
ofstream out("loto.out");
struct bilet {
	int x, y, z;
};
int main() {
	ios_base::sync_with_stdio(false);
	int n, s;
	in >> n >> s;
	map < int, bilet > h;
	for (int i = 1; i <= n; i++) {
		in >> v[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			for (int k = j; k <= n; k++) {
				if (h.find(v[i] + v[j] + v[k]) == h.end()) {
					h[v[i] + v[j] + v[k]] = {v[i], v[j], v[k]};
				}
			}
		}
	}
	for (auto it : h) {
		if (h.find(s - it.first) != h.end()) {
			out << it.second.x << " " << it.second.y << " " << it.second.z << " " << h[s - it.first].x << " " << h[s - it.first].y << " " << h[s - it.first].z << "\n";
			return 0;
		}
	}
	out << "-1\n";
	return 0;
}