Pagini recente » Cod sursa (job #1797636) | Cod sursa (job #2428431) | Cod sursa (job #2470377) | Cod sursa (job #2256927) | Cod sursa (job #2896288)
#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;
}