Cod sursa(job #2759185)
Utilizator | Data | 15 iunie 2021 21:13:09 | |
---|---|---|---|
Problema | Loto | Scor | 5 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 2.33 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("loto.in");
ofstream cout("loto.out");
int v[105],sume[1000005];
int main()
{
int n,s,m=0,ok=0;
int x,st=0,dr,mid,y;
cin>>n>>s;
for(int i=0; i<n; i++)
cin>>v[i];
for(int a=0; a<n; a++)
{
for(int b=0; b<n; b++)
{
for(int c=0; c<n; c++)
{
sume[m]=v[a]+v[b]+v[c];
m++;
}
}
}
sort(sume, sume+m);
for(int i=0; i<m; i++)
{
for(int a=0; a<n; a++)
{
for(int b=0; b<n; b++)
{
for(int c=0; c<n; c++)
{
x=s-v[a]-v[b]-v[c];
st=0;
dr=m-1;
while(st<=dr)
{
mid=(st+dr)/2;
if(v[mid]>x)
{
dr=mid-1;
}
else if(v[mid]<x)
{
st=mid+1;
}
else
{
ok=1;
y=x;
}
}
}
}
}
}
if(ok==1)
cout<<"-1";
else
{
///cout<<x<<" ";
for(int a=0; a<n; a++)
{
for(int b=0; b<n; b++)
{
for(int c=0; c<n; c++)
{
if(v[a]+v[b]+v[c]==x)
{
cout<<v[a]<<" "<<v[b]<<" "<<v[c]<<" ";
a=n;
b=n;
c=n;
}
}
}
}
for(int a=0; a<n; a++)
{
for(int b=0; b<n; b++)
{
for(int c=0; c<n; c++)
{
if(v[a]+v[b]+v[c]==s-x)
{
cout<<v[a]<<" "<<v[b]<<" "<<v[c]<<" ";
a=n;
b=n;
break;
}
}
}
}
}
return 0;
}