Cod sursa(job #3245057)

Utilizator murgurazvan991Murgu Razvan Tudor murgurazvan991 Data 27 septembrie 2024 09:13:53
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream> 
#include <unordered_map> 
using namespace std;

const int Max = 103; 
int n, s, a[Max];
using ti = tuple<int, int, int>;
unordered_map<int, ti> sume;

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

int main()
{
    fin >> n >> s;
    for (int i = 1; i <= n; ++i)
        fin >> a[i];

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            for (int k = 1; k <= n; ++k)
                {
                    int sum = a[i] + a[j] + a[k];
                    sume[sum] = {a[i], a[j], a[k]};
                }
    
    for (auto [sum, t] : sume)
    {
        auto [a, b, c] = t;
        int ramas = s - sum;
        if (sume.count(ramas))
        {
            auto [x, y, z] = sume[ramas];
            fout << a << " " << b << " " << c << " " << x << " " << y << " " << z;
            exit(0);
        }
    }
    fout << "-1";

    return 0;
}