Cod sursa(job #2896288)

Utilizator Petrica81Simion Petrica Petrica81 Data 29 aprilie 2022 21:50:04
Problema Loto Scor 95
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, vector<int>> 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[aux].empty()) {
                            loto[aux].push_back(numere[i]);
                            loto[aux].push_back(numere[j]);
                            loto[aux].push_back(numere[k]);
                        }
                        if(!loto[s-aux].empty()){
                            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;
}