Mai intai trebuie sa te autentifici.
Cod sursa(job #2895840)
Utilizator | Data | 29 aprilie 2022 15:21:48 | |
---|---|---|---|
Problema | Loto | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.97 kb |
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct jumate
{
int a, b, c;
};
unordered_map <int, jumate> sum;
int main()
{
int n, suma, i, q, w , e, temp;
f >> n >> suma;
int v[101];
for(i = 0; i < n; i++)
{
f >> v[i];
}
for(q = 0; q < n; q++)
for(w = q; w < n; w++)
for(e = w; e < n; e++)
{
sum.insert(pair<int, jumate>(v[q] + v[w] + v[e], {v[q], v[w], v[e]}));
}
bool ok = false;
for(auto it = sum.begin(); it != sum.end() && ok == false; it++)
{
temp = suma - it->first;
if(sum.find(temp) != sum.end())
{
ok = true;
g << sum[temp].a << " " << sum[temp].b << " " << sum[temp].c << " " << it->second.a << " " << it->second.b << " " << it->second.c;
}
}
if(ok == false)
g << -1;
return 0;
}