Pagini recente » Cod sursa (job #2632476) | Cod sursa (job #3222506) | Cod sursa (job #2286640) | Cod sursa (job #2632479) | Cod sursa (job #1365856)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int main()
{
int n,i,v[101],k,cnt=0,h=1,nr1=0,s,nr2=0,a[1000001],li,ls;
f>>n;
f>>k;
for(i=1; i<=n; i++)
f>>v[i];
for(i=1; i<=n; i++)
for(int j=1; j<=n; j++)
for(int t=1; t<=n; t++)
{
a[h]=v[i]+v[j]+v[t];
h++;
}
sort(a+1,a+n+1);
for(i=1; i<=h; i++)
{
int s=k-a[i];
li=1;
ls=h;
cnt=0;
while(li<=ls && cnt==0)
{
if(s<a[(li+ls)/2])
{
ls=(li+ls)/2-1;
}
else if(s>a[(li+ls)/2])
{
li=(li+ls)/2+1;
}
else
{
cnt=1;
}
}
if(cnt==1)
{
nr2=k-a[i];
nr1=a[i];
break;
}
}
if(nr1==0 && nr2==0) g<<"-1";
else for(i=1; i<=n; i++)
for(int j=1; j<=n; j++)
for(int t=1; t<=n; t++)
{
s=v[i]+v[j]+v[t];
if(s==nr1) {g<<v[i]<<" "<<v[j]<<" "<<v[t]<<" ";
nr1=-12;}
if(s==nr2){ g<<v[i]<<" "<<v[j]<<" "<<v[t]<<" ";
nr2=-12;}
}
return 0;
}