Cod sursa(job #2626226)

Utilizator Edwuard99Diaconescu Vlad Edwuard99 Data 6 iunie 2020 12:39:38
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <bits/stdc++.h>
 
using namespace std;
 
ifstream fin("loto.in");
ofstream fout("loto.out");
 
struct easy
{
    int x, y, z, val;
};
const int MOD=666013;
int n, s;
int x[101];
vector<easy>H[MOD+1];
 
inline void Insert_H(int val, int x, int y, int z)
{
    int poz=val%MOD;
    H[poz].push_back({x, y, z, val});
}
 
inline vector<easy>::iterator Check_H(int value)
{
    int poz=value%MOD;
    vector<easy>::iterator it;
    for(it=H[poz].begin(); it!=H[poz].end(); ++it)
        if(it->val==value) return it;
    return H[poz].end();
}
 
int main()
{
    fin>>n>>s;
    for(int i=1; i<=n; ++i) fin>>x[i];
    for(int i=1; i<=n; ++i)
    {
        for(int j=i; j<=n; ++j)
        {
            for(int k=j; k<=n; ++k)
            {
                int val=x[i]+x[j]+x[k];
                Insert_H(val, i, j, k);
            }
        }
    }
    for(int i=1; i<=n; ++i)
    {
        for(int j=i; j<=n; ++j)
        {
            for(int k=j; k<=n; ++k)
            {
                int val=s-x[i]-x[j]-x[k];
                if(val<0) continue;
                vector<easy>::iterator it=Check_H(val);
                if(it!=H[val%MOD].end())
                {
                    fout<<x[it->x]<<" "<<x[it->y]<<" "<<x[it->z]<<" "<<x[i]<<" "<<x[j]<<" "<<x[k]<<"\n";
                    return 0;
                }
            }
        }
    }
    fout<<"-1\n";
    return 0;
}