Pagini recente » Profil Ciurel_Alexandru_George_325CA | Monitorul de evaluare | Istoria paginii utilizator/byby | Cod sursa (job #1290640) | Cod sursa (job #973764)
Cod sursa(job #973764)
#include <fstream>
#include <algorithm>
#include <set>
#define In "loto.in"
#define Out "loto.out"
#define Nmax 2000000
using namespace std;
struct el
{
int val;
int el1;
int el2;
int el3;
bool operator< (const el E)const
{
return val<E.val;
}
};
el v[Nmax];
int a[100], N, S, n, l, r;
inline void Read()
{
ifstream f(In);
f>>N>>S;
for(int i = 1;i <= N; ++i)
f>>a[i];
f.close();
}
inline el make_el(const int x,const int y,const int z)
{
el e;
e.el1 = x;
e.el2 = y;
e.el3 = z;
e.val = x+y+z;
return e;
}
inline void Solve()
{
int i, j, k;
for(i = 1;i <= N;++i)
for(j = i;j <= N ;++j)
for(k = j;k <= N ;++k)
v[++n]=make_el(a[i],a[j],a[k]);
sort(v+1,v+n+1);
for(i = 1 ,j = n;i <= j; ++i)
{
k = S-v[i].val;
for(;i <= j && v[j].val>k; --j);
if(v[j].val==k)
{
l = i;
r = j;
return;
}
}
}
inline void Write()
{
ofstream g(Out);
if(!r)
g<<"-1\n";
else
g<<v[l].el1<<" "<<v[l].el2<<" "<<v[l].el3<<" "<<v[r].el1<<" "<<v[r].el2<<" "<<v[r].el3<<"\n";
g.close();
}
int main()
{
Read();
Solve();
Write();
return 0;
}