Cod sursa(job #670003)

Utilizator balakraz94abcd efgh balakraz94 Data 28 ianuarie 2012 09:57:21
Problema Loto Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#define infile "loto.in"
#define outfile "loto.out"
#define n_max 1005
#define MOD 666013
#define INF 1<<30
#define pb push_back
#define s_max 100000005
#define FOR(g) \
   for(vector<hash> ::iterator it = g.begin(); it!=g.end(); ++it)
using namespace std;


typedef struct hash
{
	int s, a, b, c;
};

vector < hash > H[MOD+5];

int a[n_max];

int N, S;


void citeste()
{
	freopen(infile,"r",stdin);
	
	scanf("%d %d", &N, &S);
	
	for(int i=1;i<=N;i++)
		scanf("%d",&a[i]);
	
	fclose(stdin);
}





void rezolva()
{
	freopen(outfile,"w",stdout);
	
	int where, part_sum;
	hash x;
	
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			for(int k=1;k<=N;k++)
				if(a[i]+a[j]+a[k]<=S)
				{
					x.a =a[i], x.b=a[j], x.c=a[k];
					x.s = a[i]+a[j]+a[k];
					
					where = x.s % MOD;
					H[where].pb(x);
					
					part_sum = S - x.s;
					where = part_sum % MOD;
					
					FOR(H[where])
						if((*it).s == part_sum)
						{
							printf("%d %d %d %d %d %d", (*it).a, (*it).b, (*it).c, x.a, x.b, x.c);
							return;
						}
				}
	
	printf("%d\n",-1);
}



int main()
{
	citeste();
	rezolva();
	
	fclose(stdout);
	
	return 0;
}