Cod sursa(job #2648105)

Utilizator OvidRata Ovidiu Ovid Data 8 septembrie 2020 17:10:14
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
int m1=1000159;
ifstream fin("loto.in"); ofstream fout("loto.out");
#define cin fin
#define cout fout
int t, n, m, k, a[300010], q, l, r;
struct trp{
int f; int s; int tr;
};
vector<trp> h1[1000210];
int s;





int32_t main(){
INIT
cin>>n>>s; for(int i=1; i<=n; i++){cin>>a[i];}

for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
        for(int k=1; k<=n; k++){
            if( (a[k]+a[j]+a[i])>s){continue;}
            trp ac; ac.f=a[i]; ac.s=a[j]; ac.tr=a[k];
            h1[ (a[k]+a[j]+a[i])%m1 ].pb(ac);
            if( (h1[ (s-(a[k]+a[j]+a[i]))%m1 ].size()>0) ){
                for(int l=0; l<h1[ (s-(a[k]+a[j]+a[i]))%m1 ].size(); l++){
                    auto b=h1[ (s-(a[k]+a[j]+a[i]))%m1 ][l];
                    if( ((b.f+ac.f)+(b.s+ac.s)+(b.tr+ac.tr))==s ){
                        cout<<ac.f<<" "<<ac.s<<" "<<ac.tr<<" "<<b.f<<" "<<b.s<<" "<<b.tr<<" "; return 0;
                    }
                }
            }

        }
    }
}
cout<<-1;

return 0;
}