Pagini recente » Cod sursa (job #712926) | Cod sursa (job #1800731) | Cod sursa (job #559870) | Cod sursa (job #900345) | Cod sursa (job #2745040)
#include <bits/stdc++.h>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
struct loto
{
int suma;
int x, y, z;
};
loto aux;
vector <loto> nr;
int n, s, x, v[101];
bool comp(loto a, loto b)
{
return a.suma < b.suma;
}
int main()
{
in >> n >> s;
for(int i = 0; i < n; ++i)
in >> v[i];
for(int i = 0; i < n; ++i)
for(int j = i; j < n; ++j)
for(int k = j; k < n; ++k)
{
aux.suma = v[i] + v[j] + v[k];
aux.x = v[i];
aux.y = v[j];
aux.z = v[k];
nr.push_back(aux);
}
sort(nr.begin(), nr.end(), comp);
int st, dr, ok = 0;
st = 0;
dr = nr.size() - 1;
while(st <= dr)
{
if(nr[st].suma + nr[dr].suma > s)
dr--;
else if(nr[st].suma + nr[dr].suma < s)
st++;
else
{
out << nr[st].x << " " << nr[st].y << " " << nr[st].z << " " << nr[dr].x << " " << nr[dr].y << " " << nr[dr].z;
ok = 1;
break;
}
}
if(!ok)
out << -1;
return 0;
}