Cod sursa(job #809565)

Utilizator matei_cChristescu Matei matei_c Data 8 noiembrie 2012 17:55:39
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.42 kb
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std ;

#define maxn 101
#define mod 2000003

/*
struct aaa
{
	int suma, a, b, c ; 
	
};	
*/

int n, s ;
int a[maxn] ;
vector <int> hash[mod] ; 

int main()
{
	
	freopen("loto.in", "r", stdin);
	freopen("loto.out", "w", stdout);
	
	scanf("%d%d", &n, &s);
	
	for( int i = 1 ; i <= n ; ++ i )
		scanf("%d", &a[i]);
	
	for( int i = 1 ; i <= n ; ++ i )
	{
		for( int j = 1 ; j <= n ; ++ j )
		{
			for( int k = 1 ; k <= n ; ++ k )
			{
				
				int sum = a[i] + a[j] + a[k] ;
				
				if( sum > s )
					continue ;
				
				int r = sum % mod ;
				/*
				aaa abc;
				abc.suma = sum;
				abc.a = a[i] ;
				abc.b = a[j] ;
				abc.c = a[k] ;
				*/
				hash[r].push_back( sum ) ;
			
			}	
		}	
	}
	
	for( int u = 1 ; u <= n ; ++ u )
	{
		for( int v = 1 ; v <= n ; ++ v )
		{
			for( int w = 1 ; w <= n ; ++ w )
			{
			
				int SUMA = a[u] + a[v] + a[w] ;
				
				int scaut = s - SUMA ;
					
				if( scaut < 0 )
					continue ;
					
				int rcaut = scaut % mod ;
			
				for( size_t k = 0 ; k < hash[rcaut].size() ; ++k )
				{
				
					if( hash[rcaut][k] == scaut )
					{
						printf("%d %d %d ", a[u], a[v], a[w]);
						//printf("%d %d %d\n",hash[rcaut][k].a, hash[rcaut][k].b, hash[rcaut][k].c);
						return 0 ;
					}
				
				}
			
			}
		}
	}	
	
	printf("-1\n");
	
	return 0;
	
}