Cod sursa(job #2896473)

Utilizator alexdn6Dina Alexandru alexdn6 Data 29 aprilie 2022 23:20:01
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;
ifstream f ("loto.in");
ofstream g ("loto.out");
vector <int> v;
unordered_map<int, int[3]> loto;
int n, x, y, z;
long long s, s1, d;
int main() {
    f >> n;
    f >> s;
    for(int i = 0; i < n; i++) {
        int nr;
        f >> nr;
        v.push_back(nr);
    }
    for(x = 0; x < n; x++)
        for(y = x; y < n; y++)
            for(z = y; z < n; z++) {
                        s1 = v[x] + v[y] + v[z];
                        loto[s1][0] = v[x];
                        loto[s1][1] = v[y];
                        loto[s1][2] = v[z];
                    }
    for(x = 0; x < n; x++)
        for(y = x; y < n; y++)
            for(z = y; z < n; z++) {
                d = s - (v[x] + v[y] + v[z]);
                if(loto.find(d) != loto.end()) {
                    g << v[x] << " " << v[y] << " " << v[z] << " " << loto[d][0] << " " << loto[d][1] << " " << loto[d][2];
                    return 0;
                }
            }
    g << -1;
    return 0;
}