Pagini recente » Cod sursa (job #1719088) | Cod sursa (job #630768) | Cod sursa (job #1598040) | Cod sursa (job #18440) | Cod sursa (job #1052521)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
long long n, S, v[10000], i, j, x, y;
struct punct
{
int a,b,c,s;
}a[1000000];
bool cmp(punct x, punct y)
{
return x.s<y.s;
}
int cb(int st, int dr, int sum)
{
int m;
while(st<=dr)
{
m=(st+dr)/2;
if(a[m].s==sum)
return m;
if(a[m].s<sum)
st=m+1;
if(a[m].s>sum)
dr=m-1;
}
return 0;
}
int main()
{
f>>n>>S;
for(i=1;i<=n;i++)
f>>v[i];
int p=0;
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
for(int x=j;x<=n;x++)
{
p++;
a[p].a=v[i];
a[p].b=v[j];
a[p].c=v[x];
a[p].s=v[i]+v[j]+v[x];
}
sort(a+1,a+p+1,cmp);
int c; bool ok=false;
for(int i=1;i<=p;i++)
{
c=cb(1,p,S-a[i].s);
if(c!=0)
{
g<<a[i].a<<' '<<a[i].b<<' '<<a[i].c<<' '<<a[c].a<<' '<<a[c].b<<' '<<a[c].c;
ok=true;
break;
}
}
if(ok==false)
g<<-1;
f.close();
g.close();
return 0;
}