Cod sursa(job #3280275)

Utilizator mihai_bosIancu Mihai mihai_bos Data 25 februarie 2025 22:31:50
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
#include <unordered_map>

using namespace std;

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

struct three{
    int x, y, z;
};

int n, s, v[105];
unordered_map <int, three> mapa;
bool ok ;

int main()
{
    cin >> n >> s;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            for(int k = 1; k <= n; ++k)
                mapa[v[i] + v[j] + v[k]] = {v[i], v[j], v[k]};
    for(int i = 1; i <= n; ++i) {
        if(ok) break;
        for(int j = 1; j <= n; ++j) {
            if(ok) break;
            for(int k = 1; k <= n; ++k) {
                int remainder = s - (v[i] + v[j] + v[k]);
                if(mapa.find(remainder) != mapa.end()) {
                    cout << v[i] << " " << v[j] << " " << v[k] << " " << mapa[remainder].x << " " << mapa[remainder].y <<" " << mapa[remainder].z;
                    ok = 1;
                    break;
                }
            }
        }
    }
    if(!ok) cout << -1;

    return 0;
}