Cod sursa(job #2894666)

Utilizator AdelaCorbeanuAdela Corbeanu AdelaCorbeanu Data 28 aprilie 2022 00:57:49
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <fstream>
#include <unordered_set>

std::unordered_set<long long> hash(100100);
int v[101];

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

    int n, s;
    fin >> n >> s;

    for (int i = 1; i <= n; ++i) fin >> v[i];

    for (int i = 1; i <= n; ++i)
        for (int j = i; j <= n; ++j)
            for (int h = j; h <= n; ++h)
                hash.insert(v[i] + v[j] + v[h]);

    bool continua = true;
    for (auto it : hash) {
        if (!continua) break;
        if (hash.find(s - it) != hash.end()) {
            for (int i = 1; i <=n && continua; ++i)
                for (int j = i; j <= n && continua; ++j)
                    for (int h = j; h <= n; ++h)
                        if (v[i] + v[j] + v[h] == s - it) {
                            fout << v[i] << " " << v[j] << " " << v[h] << " ";
                            continua = false;
                            break;
                        }

            if (!continua) {
                for (int i = 1; i <= n; ++i)
                    for (int j = i; j <= n; ++j)
                        for (int h = j; h <= n; ++h)
                            if (v[i] + v[j] + v[h] == it) {
                                fout << v[i] << " " << v[j] << " " << v[h];
                            }
            }
        }
    }

    if (continua) fout << -1;

    return 0;
}