Cod sursa(job #2746246)

Utilizator serafimalex2001Serafim Alex serafimalex2001 Data 27 aprilie 2021 17:20:52
Problema Loto Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;

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

struct triplet{
    int a,b,c;
};

unordered_map<int, triplet> M;

void Do(){
    int n,s,x, sum,ct = 0;
    triplet t;
    vector<int>v;
    fin >> n >> s;
    for(int i = 0; i<n; ++i){
        fin >> x;
        v.push_back(x);
    }
    for(int i = 0; i<n && ct == 0; ++i)
        for(int j = 0; j<n && ct == 0; ++j)
            for(int k = 0; k<n && ct == 0; ++k){
                sum = v[i] + v[j] + v[k];
                t.a = v[i];
                t.b = v[j];
                t.c = v[k];
                if(M.find(s-sum) != M.end()){
                    ct ++;
                    fout << M[s-sum].a << " " << M[s-sum].b << " " << M[s-sum].c << " " << t.a <<" "<<t.b << " " << t.c;
                }
                if(M.find(sum) != M.end())
                    continue;
                else M[sum] = t;
            }
    if(ct == 0)
        fout << -1;
}

int main()
{
    Do();
    return 0;
}