Cod sursa(job #2735094)

Utilizator davidbejenariu2David Bejenariu davidbejenariu2 Data 1 aprilie 2021 20:09:58
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>

using namespace std;

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

int n, S;
vector <int> v(100);
unordered_map <int, pair <int, int>> mp;

int main()
{
    fin >> n >> S;

    for (int i = 0; i < n; ++i)
        fin >> v[i];

    fin.close();

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                mp[v[i] + v[j] + v[k]] = make_pair(v[i], v[j]);

    bool found = false;

    for (int i = 0; i < n && !found; ++i)
        for (int j = 0; j < n && !found; ++j)
            for (int k = 0; k < n && !found; ++k)
                if (mp.find(S - v[i] - v[j] - v[k]) != mp.end())
                {
                    fout << v[i] << ' ' << v[j] << ' ' << v[k] << ' ' << mp[S - v[i] - v[j] - v[k]].first << ' '
                         << mp[S - v[i] - v[j] - v[k]].second << ' ' << S - v[i] - v[j] - v[k] - mp[S - v[i] - v[j] - v[k]].first - mp[S - v[i] - v[j] - v[k]].second;

                    found = 1;
                }

    if (!found) fout << -1;
    fout.close();

    return 0;
}