Pagini recente » Cod sursa (job #2035915) | Cod sursa (job #1714587) | Cod sursa (job #71221) | Cod sursa (job #2081083) | Cod sursa (job #2740924)
#include <cmath>
#include <fstream>
#include <vector>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
struct tripla {
int x, y, z;
};
int n, S;
int v[101];
map<int, tripla> mp;
bool ok = 0;
int rez[7];
void read() {
int i;
ifstream f("loto.in");
f >> n >> S;
for (i = 1; i <= n; i++)
f >> v[i];
f.close();
}
void solve() {
int i, j, k;
for (i = 1; i <= n; i++)
for (j = i; j <= n; j++)
for (k = j; k <= n; k++)
mp[v[i] + v[j] + v[k]] = {i, j, k};
for (auto it = mp.begin(); it != mp.end(); it++)
if (mp[S - it->first].x != 0 && it->second.x != 0) {
rez[1] = it->second.x, rez[2] = it->second.y, rez[3] = it->second.z;
rez[4] = mp[S - it->first].x, rez[5] = mp[S - it->first].y, rez[6] = mp[S - it->first].z;
ok = 1;
break;
}
}
void output() {
ofstream g("loto.out");
if (!ok)
g << -1;
else {
int i;
for (i = 1; i <= 6; i++)
g << v[rez[i]] << ' ';
}
g.close();
}
int main() {
read();
solve();
output();
return 0;
}