Pagini recente » Cod sursa (job #1692517) | Cod sursa (job #2441361) | Cod sursa (job #1117781) | Cod sursa (job #3246982) | Cod sursa (job #2896304)
#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;
}