Cod sursa(job #2746280)

Utilizator serafimalex2001Serafim Alex serafimalex2001 Data 27 aprilie 2021 17:41:01
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 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;
unordered_map<int, triplet>::iterator it;
unordered_map<int, triplet>::iterator it2;

void Do(){
    int n,s,x, sum,ct = 0;
    triplet t, p;
    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; ++i)
        for(int j = i; j<n; ++j)
            for(int k = j; k<n; ++k){
                sum = v[i] + v[j] + v[k];
                t.a = v[i];
                t.b = v[j];
                t.c = v[k];
                if(M.find(sum) != M.end())
                    continue;
                else M[sum] = t;
            }
    for(it = M.begin(); it != M.end(); ++it){
        it2 = M.find(s - it->first);
        if( it2!=M.end() ){
            t = it->second;
            p = it2->second;
            fout << t.a << " "<< t.b <<" "<<t.c <<" " << p.a <<" " << p.b <<" "<<p.c;
            ct = 1;
            break;
        }
    }
    if(ct == 0)
        fout << -1;
}

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