Cod sursa(job #2896304)

Utilizator Petrica81Simion Petrica Petrica81 Data 29 aprilie 2022 21:56:21
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int n,s,aux;
unordered_map<int, int[3]> loto;
vector<int> numere;
int main() {
    f >> n >> s;
    for (int i = 0; i < n; i++) {
        f >> aux;
        numere.push_back(aux);
    }
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            for (int k = j; k < n; k++) {
                if (numere[i] + numere[j] + numere[k] < s) {
                        aux = numere[i] + numere[j] + numere[k];
                        if(loto.find(aux) == loto.end()) {
                            loto[aux][0] = numere[i];
                            loto[aux][1] = numere[j];
                            loto[aux][2] = numere[k];
                        }
                        if(loto.find(s-aux) != loto.end()){
                            g<<loto[aux][0]<<" "<<loto[aux][1]<<" "<<loto[aux][2]<<" "<<loto[s-aux][0]<<" "<<loto[s-aux][1]<<" "<<loto[s-aux][2];
                            return 0;
                        }
                }
            }
        }
    }
    g<<-1;
    return 0;
}