Cod sursa(job #2716821)

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

using namespace std;

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

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

int main()
{

    int n, s;
    cin >> n >> s;

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

    map<int, trio> all;
    unordered_set<int> vals;

    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 && vals.find(val) == vals.end()) {
                    vals.insert(val);
                    all.insert({val, {numb[i], numb[j], numb[k]}});
                }
            }
        }
    }

    for (auto it1:all) {
        auto it2 = all.find(s - it1.first);

        if (it2 != all.end()) {
            it1.second.write();
            it2->second.write();
            return 0;
        }

    }

    cout << -1;

    return 0;
}