Cod sursa(job #1618098)

Utilizator al.mocanuAlexandru Mocanu al.mocanu Data 27 februarie 2016 18:13:26
Problema Loto Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <stdio.h>
#include <set>
#include <vector>
#define MAX 105
#define pis pair<int, vector<int> >
#define mk make_pair
using namespace std;

struct compar{
	bool operator() (const pis& a, const pis& b){
		return a.first < b.first;
	}
};

int n, s, v[MAX];
set<pis, compar> l;

int main(){
	freopen("loto.in", "r", stdin);
	freopen("loto.out", "w", stdout);
	scanf("%d%d", &n, &s);
	for(int i = 0; i < n; i++)
		scanf("%d", &v[i]);
	for(int i = 0; i < n; i++)
		for(int j = i; j < n; j++)
			for(int k = j; k < n; k++){
				int sum = v[i] + v[j] + v[k];
				vector<int> x;
				x.push_back(v[i]);
				x.push_back(v[j]);
				x.push_back(v[k]);
				l.insert(mk(sum, x));
			}

	set<pis>::iterator it1, it2;
	for(it1 = l.begin(); it1 != l.end(); it1++){
		pis ref;
		ref.first = s - it1->first;
		it2 = l.find(ref);
		if(it2 != l.end()){
			printf("%d %d %d %d %d %d\n", it1->second[0], it1->second[1], 
				it1->second[2], it2->second[0], it2->second[1], it2->second[2]);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}