Cod sursa(job #1618116)

Utilizator al.mocanuAlexandru Mocanu al.mocanu Data 27 februarie 2016 18:20:03
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <stdio.h>
#include <set>
#include <vector>
#define MAX 105
using namespace std;

typedef struct{
	int val;
	int x, y, z;
} Elem;

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

int n, s, v[MAX];
set<Elem, 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++){
				Elem a;
				a.val = (a.x = v[i]) + (a.y = v[j]) + (a.z = v[k]);
				l.insert(a);
			}

	set<Elem, compar>::iterator it1, it2;
	for(it1 = l.begin(); it1 != l.end(); it1++){
		Elem ref;
		ref.val = s - it1->val;
		it2 = l.find(ref);
		if(it2 != l.end()){
			printf("%d %d %d %d %d %d\n", it1->x, it1->y, it1->z, 
				it2->x, it2->y, it2->z);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}