Cod sursa(job #2746764)

Utilizator Pop_MariaPop Maria Pop_Maria Data 28 aprilie 2021 14:06:25
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <unordered_map>

using namespace std;

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

unordered_map <int, semi_suma> map_suma;
int v[100], n, s;

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

    semi_suma ob;
    fin >> n >> s;

    for(int i = 0; i < n; i++)
    {
        fin >> v[i];
    }

    for(int i = 0; i < n; i++)
    {
        for(int j = i; j < n; j++)
        {
            for(int k = j; k < n; k++)
            {
                ob.a = v[i];
                ob.b = v[j];
                ob.c = v[k];

                int suma = v[i] + v[j] + v[k];
                map_suma.insert({suma, ob});

                if(map_suma.find(s - suma) != map_suma.end())
                {
                    fout << map_suma[suma].a << " " << map_suma[suma].b << " " << map_suma[suma].c << " " << map_suma[s - suma].a << " " << map_suma[s - suma].b << " " << map_suma[s - suma].c;
                    return 0;
                }
            }
        }
    }

    fout << -1;
}