Cod sursa(job #3131678)

Utilizator Nicoleta114Caramaliu Nicoleta Nicoleta114 Data 21 mai 2023 03:44:35
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <fstream>
#include <map>
#include <vector>

using namespace std;

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

int main() {
    int N, S, x;
    fin >> N >> S;

    vector<int> numere;
    for (int i = 0; i < N; i++) {
        fin >> x;
        numere.push_back(x);
    }

    map<int, pair<int, pair<int, int>>> combinatii;

    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            for (int k = j; k < N; k++) {
                int suma = numere[i] + numere[j] + numere[k];
                combinatii[suma] = make_pair(numere[i], make_pair(numere[j], numere[k]));
            }
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            for (int k = j; k < N; k++) {
                int dif = S - numere[i] - numere[j] - numere[k];
                if (combinatii.count(dif) > 0) {
                    pair<int, pair<int, int>> rsp = combinatii[dif];
                    fout << numere[i] << " " << numere[j] << " " << numere[k] << " "
                         << rsp.first << " " << rsp.second.first << " " << rsp.second.second;
                    return 0;
                }
            }
        }
    }

    fout << -1;

    return 0;
}