Cod sursa(job #1051658)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 10 decembrie 2013 13:09:58
Problema Loto Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.72 kb
#include <fstream>
#include <vector>


using namespace std;

const int mod = 666013;
const int MAX_N = 110;
int A[MAX_N];
vector <pair< int, int > > H[mod];
vector <pair< int, int > >::iterator it;


inline int max( int x, int y ){

    if( x > y ) return x;
    return y;
}

int main(){
    
    ifstream cin( "loto.in" );
    ofstream cout( "loto.out" );

    int N, S, max_v = 0;
    cin >> N >> S;
    for( int i = 1; i <= N; ++i ){

        cin >> A[i];
        max_v = max( max_v, A[i] );
        }
    if( max_v * 6 < S ){

        cout << -1;
        return 0;
        }
    for( int i = 1; i <= N; ++i )
        for( int j = 1; j <= N; ++j )
            for( int h = 1; h <= N; ++h ){
                
                int s = A[i] + A[j] + A[h];
                int r = s % mod;
                bool e = false;
                if( H[r].size() > 0 )
                    for( it = H[r].begin(); it != H[r].end(); ++it )
                        if( (*it).first == s ) e = true;
                if( !e ) H[r].push_back( make_pair( s, ( i * 100 + j ) * 100 + h ) );
                }
    for( int i = 1; i <= N; ++i )
        for( int j = 1; j <= N; ++j )
            for( int h = 1; h <= N; ++h ){
                
                int s = S - A[i] - A[j] - A[h];
		        int r = s % mod, v = 0;
    		    if( s > 0 && H[r].size() > 0 )
        	    for( it = H[r].begin(); it != H[r].end(); ++it )
            		if( (*it).first == s  ) v = (*it).second;
                if( v != 0 ){
                    
                    cout << A[i] << " " << A[j] << " " << A[h] << " " << A[v%100] << " " << A[v/100%100] << " " << A[v/10000%100];
                    return 0;
                    } 
                }

    cout.close();
    cin.close();
    return 0;
}