Cod sursa(job #2745499)

Utilizator lalalaura_02Udroiu Laura-Ioana lalalaura_02 Data 26 aprilie 2021 16:59:46
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("loto.in");
ofstream g("loto.out");

struct triplete
{
    int x, y, z;
};

unordered_map <int, triplete> suma;

int main()
{
    int v[101], n, s, ok = 0;
    f >> n >> s;
    for(int i = 0; i < n; i++)
        f >> v[i];

    for(int i = 0; i < n; i++)
        for(int j = i; j < n; j++)
            for(int k = j; k < n; k++)
                suma[v[i] + v[j] + v[k]] = {v[i], v[j], v[k]}; //calculam sumele posibile

    for(auto i: suma) //parcurgem map ul
        if(suma.end()!= suma.find(s-i.first))//gasim "complementarul" si ne oprim
        {
            g << suma[s-i.first].x << " " << suma[s-i.first].y << " " << suma[s-i.first].z << " " << i.second.x << " " << i.second.y << " " << i.second.z;
            ok = 1;
            break;
        }
    if(!ok) //inseamna ca n am gasit nicio varianta
        g << -1;
    return 0;
}