Cod sursa(job #200308)

Utilizator tvladTataranu Vlad tvlad Data 23 iulie 2008 12:29:33
Problema Loto Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <cstdio>
#include <map>
using namespace std;

const int N = 100;

struct triplet {
	int x,y,z;
	triplet() {};
	triplet ( int a, int b, int c ) { x = a; y = b; z = c; };
};

int n, s;
int v[N];
map<int, triplet> m;

int main() {
	freopen("loto.in","rt",stdin);
	freopen("loto.out","wt",stdout);
	scanf("%d %d",&n,&s);
	for (int i = 0; i < n; ++i) scanf("%d",&v[i]);

	map<int, triplet>::iterator wh;
	for (int i = 0,j,k,sum; i < n; ++i) {
		for (j = 0; j < n; ++j) {
			for (k = 0; k < n; ++k) {
				sum = v[i]+v[j]+v[k];
				m[sum] = triplet(i,j,k);
				wh = m.find(s-sum);
				if (wh != m.end()) {
					printf("%d %d %d %d %d %d\n",v[i],v[j],v[k],v[wh->second.x],v[wh->second.y],v[wh->second.z]);
					return 0;
				}
			}
		}
	}
	printf("-1\n");
	return 0;
}