Cod sursa(job #3131974)

Utilizator LazarDanielGabrielLazar Daniel-Gabriel LazarDanielGabriel Data 21 mai 2023 22:11:45
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <unordered_set>
#include <vector>

using namespace std;

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

    int N;
    long long S;
    fin >> N >> S;

    vector<long long> loto(N);
    unordered_set<long long> sums;
    bool found = false;

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

    for (int i = 0; i < N && !found; i++) {
        for (int j = 0; j < N && !found; j++) {
            for (int k = 0; k < N && !found; k++) {
                long long sum = loto[i] + loto[j] + loto[k];

                if (sums.count(S - sum)) {
                    found = true;
                    fout << loto[i] << " " << loto[j] << " " << loto[k] << " ";
                    fout << loto[i] << " " << loto[j] << " " << loto[k];
                }

                sums.insert(sum);
            }
        }
    }

    if (!found) {
        fout << -1;
    }

    fin.close();
    fout.close();

    return 0;
}