Pagini recente » Profil Pepelea_Flaviu | Profil stefdascalescu | ONIS 2014, Clasament Final | Profil Pepelea_Flaviu | Cod sursa (job #322445)
Cod sursa(job #322445)
#include<fstream>
#include<algorithm>
#define maxn 101
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct elem
{
int s,x,y,z;
} a[maxn*maxn*maxn];
int i,j,n,s,k,r[maxn],p,x,y,sor[maxn*maxn*maxn];
bool fcomp(int x,int y)
{
return a[x].s<a[y].s;
}
int main()
{
f>>n>>s;
for(i=1;i<=n;++i)
f>>r[i];
for(i=1;i<=n;++i)
for(j=1;j<=n;++j)
for(k=1;k<=n;++k)
a[++p].x=r[i],a[p].y=r[j],a[p].z=r[k],a[p].s=r[i]+r[j]+r[k],sor[p]=p;
sort(sor+1,sor+p+1,fcomp);
x=1;
y=p;
while(x<=y)
if(a[sor[x]].s+a[sor[y-1]].s>=s)
--y;
else
if(a[sor[x]].s+a[sor[y]].s==s)
{
g<<a[sor[x]].x<<" "<<a[sor[x]].y<<" "<<a[sor[x]].z<<" "<<a[sor[y]].x<<" "<<a[sor[y]].y<<" "<<a[sor[y]].z<<"\n";
f.close();
g.close();
return 0;
}
else
++x;
g<<"-1\n";
f.close();
g.close();
return 0;
}