Cod sursa(job #2781124)

Utilizator Andrei_ierdnANeculau Rares-Andrei Andrei_ierdnA Data 8 octombrie 2021 16:08:22
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
///95 pct

#include <fstream>
#include <unordered_map>

using namespace std;

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

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

triplet t = {-1, -1, -1};

unordered_map<int, triplet> fr;

int n, s, i, j, k, a[102], dif;

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

    for (i = 1; i <= n; i++)
        for (j = i; j <= n; j++)
            for (k = j; k <= n; k++)
                fr[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};

    for (i = 1; i <= n; i++) {
        for (j = i; j <= n; j++) {
            for (k = j; k <= n; k++) {
                dif = s - a[i] - a[j] - a[k];
                if (fr.count(dif) > 0) {
                    t = fr[dif];
                    g << a[i] << ' ' << a[j] << ' ' << a[k] << ' ';
                    g << t.x << ' ' << t.y << ' ' << t.z;
                    k = n + 1;
                    j = n + 1;
                    i = n + 1;
                }
            }
        }
    }

    if (t.x == -1 && t.y == -1 && t.z == -1)
        g << -1;
    f.close();
    g.close();
    return 0;
}