Cod sursa(job #3131932)

Utilizator lucapetchiPetchi Andrei Luca lucapetchi Data 21 mai 2023 21:44:05
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
using namespace std;
#include  <fstream>
#include <vector>
#include <unordered_map>
ofstream out("loto.in");
ifstream in("loto.out");



int n, s, V[100];
unordered_map<int, int[3]> T;

int main() {

    in >> n >> s;
    for (int i = 0; i < n; i++)
        in >> V[i];


    bool comb = 0;
    for (int i = 0; i < n && !comb; i++)
        for (int j = i; j < n && !comb; j++)
            for (int k = j; k < n && !comb; k++) {
                T[V[i] + V[j] + V[k]][0] = V[i];
                T[V[i] + V[j] + V[k]][1] = V[j];
                T[V[i] + V[j] + V[k]][2] = V[k];

                int dif = s - V[i] - V[j] - V[k];
                if (T.find(dif) != T.end()) {
                    comb = 1;
                    out << V[i] << ' ' << V[j] << ' ' << V[k] << ' ' << T[dif][0] << ' ' <<
                        T[dif][1] << ' ' << T[dif][2] << '\n';
                }
            }

    if (!comb)
        out << -1;
    return 0;
}