Cod sursa(job #2835791)

Utilizator AswVwsACamburu Luca AswVwsA Data 19 ianuarie 2022 11:20:01
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <unordered_map>
using namespace std;

ifstream cin("loto.in");
ofstream cout("loto.out");


struct sol
{
    int x, y, z;
};
unordered_map <int, sol> m;
const int NMAX = 103;
int v[NMAX];
int main()
{
    int n, s, i, j, k;
    cin >> n >> s;
    for (i = 1; i <= n; i++)
        cin >> v[i];
    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
            for (k = 1; k <= n; k++)
            {
                sol aux;
                aux.x = v[i];
                aux.y = v[j];
                aux.z = v[k];
                m[v[i] + v[j] + v[k]] = aux;
            }
    unordered_map <int, sol> :: iterator it, where;
    for (it = m.begin(); it != m.end(); it++)
    {/*
        cout << it->first << " ";
        cout << it->second.x << " " << it->second.y << " " << it->second.z << "\n";
    */
        where = m.find(s - it->first);
        if (where != m.end())
        {
            cout << (it->second).x << " " << (it->second).y << " " <<
                 (it->second).z << " ";
            cout << where->second.x << " " << where->second.y << " " <<
                where->second.z;
            return 0;
        }
    }
    cout << -1;
}