Cod sursa(job #2716829)

Utilizator CharacterMeCharacter Me CharacterMe Data 5 martie 2021 18:47:39
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <bits/stdc++.h>

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

struct trio{
    int first;
    int second;
    int third;

    void write() {
        fout << first << " " << second << " " << third << " ";
    }
};

int main()
{

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

    vector<int> numb(n);
    for (int i = 0; i < n; ++i) {
        fin >> numb[i];
    }

    sort(numb.begin(), numb.end());

    map<int, trio> all;

    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            for (int k = j; k < n; ++k) {
                int val = numb[i] + numb[j] + numb[k];
                if (val <= s && all.find(val) == all.end()) {
                    all.insert({val, {numb[i], numb[j], numb[k]}});

                    auto it = all.find(s - val);
                    if (it != all.end()) {
                        fout << numb[i] << " " << numb[j] << " " << numb[k] << " ";
                        it->second.write();
                        return 0;
                    }
                }
            }
        }
    }

    fout << -1;

    return 0;
}