Cod sursa(job #1283824)

Utilizator toniobFMI - Barbalau Antonio toniob Data 6 decembrie 2014 01:33:06
Problema Loto Scor 0
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 0.86 kb
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;

ifstream in("loto.in");
ofstream out("loto.out");
int n, s, v[10000];
unordered_map<int, vector<int> > h;

void read(){
	in >> n >> s;
	for (int i = 1; i <= n; ++i) {
		in >> v[i];
	}
}

void calc_sums(){
	for (int i = 1; i <= n; ++i){
		for (int j = 1; j <= n; ++j){
			for (int k = 1; k <= n; ++k){
				h[ v[i]+v[j]+v[k] ] = { i, j, k };
			}
		}
	}
}

void print_sol(){
	for (unordered_map<int, vector<int> >::iterator it = h.begin(), res; it != h.end(); ++it){
		res = h.find(s - it->first);
		if (res != h.end()) {
			vector<int> init = it->second, resv = res->second;
			out << init[0] << ' ' << init[1] << ' ' << init[2] << ' ';
			out << resv[0] << ' ' << resv[1] << ' ' << resv[2];
			return;
		}
	}
	out << "NUHAHA";
}

int main(){
	read();

	calc_sums();

	print_sol();

	return 0;
}