Cod sursa(job #2746463)

Utilizator Virgil993Virgil Turcu Virgil993 Data 27 aprilie 2021 21:51:18
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <iostream>
#include<bits/stdc++.h>
#include<fstream>

using namespace std;

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

struct suma_trei
{
    int a;
    int b;
    int c;
};

unordered_map<int, suma_trei> mp;
unordered_map<int,suma_trei>::iterator it;
unordered_map<int,suma_trei>::iterator it2;

void rezolva()
{


    vector<int> v;
    int n, s;
    int suma_curenta;
    suma_trei t;
    suma_trei t1,t2;
    int x;
    fin>>n>>s;
    for(int i=0;i<n;i++)
    {

        fin>>x;
        v.push_back(x);
    }
    //memoram toate sumele posibile cu 3 elemente
    for(int i=0;i<v.size();i++)
        for(int j=0;j<v.size();j++)
            for(int k=0;k<v.size();k++)
    {

        suma_curenta = v[i] + v[j] + v[k];
        t.a = v[i];
        t.b = v[j];
        t.c = v[k];
        if(mp.find(suma_curenta) == mp.end())
            mp[suma_curenta] = t;
        else
            continue;

    }
    int ok = 0;
    for(it2 = mp.begin();it2!=mp.end();it2++)
    {
        it = mp.find(s - it2 -> first);
        if(it != mp.end())
        {

            t1 = it -> second;
            t2 = it2 -> second;
            fout<<t1.a<<" "<<t1.b<<" "<<t1.c<<" "<<t2.a<<" "<<t2.b<<" "<<t2.c<<" ";
            ok = 1;
            break;
        }
    }
    if(ok == 0)
        fout<<-1;
}

int main()
{


    rezolva();
    return 0;
}