Cod sursa(job #2841137)

Utilizator gripzStroescu Matei Alexandru gripz Data 29 ianuarie 2022 12:31:34
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <iostream>
#include <unordered_map>

using namespace std;

struct pereche {
    int i = -1;
    int j = -1;
    int k = -1;
    int sum = 0;
};

unordered_map<int, pereche> mp;

int main() {
    freopen("loto.in", "r", stdin);
    freopen("loto.out", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, S;
    int nr[100];

    cin >> N >> S;
    for (int i = 1; i <= N; i++) {
        cin >> nr[i];
    }

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            for (int k = 1; k <= N; k++) {
                pereche p;
                p.i = nr[i];
                p.j = nr[j];
                p.k = nr[k];
                p.sum = nr[i] + nr[j] + nr[k];
                mp[p.sum] = p;
            }

    for (auto &entry : mp) {
        int sum = entry.second.sum;
        int sn = S - sum;
        if (mp[sn].i != -1) {
            {
                cout << entry.second.i << " " << entry.second.j << " "
                     << entry.second.k << " ";
                cout << mp[sn].i << " " << mp[sn].j << " " << mp[sn].k << " ";
                return 0;
            }
        }
    }

    cout << -1;
    return 0;
}