Cod sursa(job #3347327)

Utilizator serbanbBrindescu Serban serbanb Data 16 martie 2026 11:47:32
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.7 kb
#include <fstream>
#include <unordered_map>
#include <vector>
#include <algorithm>

using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

struct sum
{
    int a1,a2,a3;
};

int n, S;
long long int v[105];
unordered_map<long long int, sum> m;

void precalculate3()
{
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = 0; k < n; ++k){
                sum Sum;
                long long int x;
                x = v[i] + v[j] + v[k];
                Sum.a1 = v[i];
                Sum.a2 = v[j];
                Sum.a3 = v[k];
                m[x] = Sum;
            }
        }
    }
}

void generate3()
{
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = 0; k < n; ++k){
                long long int x;
                x = v[i] + v[j] + v[k];
                if(m.count(S - x) && m[S - x].a1 + m[S - x].a2 + m[S - x].a3 == S - x){
                    vector<int> temp;
                    temp.push_back(v[i]);
                    temp.push_back(v[j]);
                    temp.push_back(v[k]);
                    temp.push_back(m[S - x].a1);
                    temp.push_back(m[S - x].a2);
                    temp.push_back(m[S - x].a3);
                    sort(temp.begin(), temp.end());
                    for(int idx = 0; idx < 6; ++idx){
                        fout << temp[idx] << ' ';
                    }
                    return;
                }
            }
        }
    }
    fout << -1;
}

int main()
{
    fin >> n >> S;
    for(int i = 0; i < n; ++i){
        fin >> v[i];
    }
    precalculate3();
    generate3();
    return 0;
}