Cod sursa(job #2745494)

Utilizator NSA-16Neacsu-Tranciuc Sasa-Andrei NSA-16 Data 26 aprilie 2021 16:51:17
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int main()
{
int n, s;
int l[100];
unordered_map <int, int[3]> map;
    f >> n >> s;
    for (int c = 0; c < n; c++)
    {
        f >> l[c];
    }
    for (int c = 0; c < n; c++)
        for (int d = c; d < n; d++)
            for (int e = d; e < n; e++)
            {
                int s2 = l[c] + l[d] + l[e];
                if(!map.count(s2) && s2 < s)
                {
                    map[s2][0] = c;
                    map[s2][1] = d;
                    map[s2][2] = e;
                }
                int s3 = s - s2;
                if(s3 > 0 && map.count(s3))
                {
                    g << l[map[s3][0]] << ' ' << l[map[s3][1]] << ' ' << l[map[s3][2]] << ' ' << l[c] << ' ' << l[d] << ' '<< l[e];
                    return 0;
                }
            }
    g << -1;
    return 0;
}