Cod sursa(job #2734361)

Utilizator LordNecrateBiowCuciureanu Dragos-Adrian LordNecrateBiow Data 31 martie 2021 19:19:29
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>

using namespace std;

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

vector <int> v;

struct elem 
{
    bool apare = false;
    int first, second, third;
};

unordered_map <int, elem> has;

int loto(int n, int s)
{
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            for (int k = 0; k < n; k++)
            {
                has[v[i] + v[j] + v[k]].apare = true;
                has[v[i] + v[j] + v[k]].first = v[i];
                has[v[i] + v[j] + v[k]].second = v[j];
                has[v[i] + v[j] + v[k]].third = v[k];
            }
    for (int i = 0; i < s / 2; i++)
    {
        if (has[i].apare == true && has[s - i].apare == true) 
        {
            fout << has[i].first << " " << has[i].second << " " << has[i].third << " ";
            fout << has[s - i].first << " " << has[s - i].second << " " << has[s - i].third;
            return 1;
        }
    }
    fout << -1;
    return 1;
}

int main()
{
    int n, s;
    fin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        int x;
        fin >> x;
        v.push_back(x);
    }
    loto(n, s);
}