Pagini recente » Cod sursa (job #2018806) | Cod sursa (job #723025) | Stalpisori | Statistici Sofian Rosa (Rosa) | Cod sursa (job #322444)
Cod sursa(job #322444)
#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;
bool fcomp(elem a,elem b)
{
return a.s<b.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];
sort(a+1,a+p+1,fcomp);
x=1;
y=p;
while(x<=y)
if(a[x].s+a[y-1].s>=s)
--y;
else
if(a[x].s+a[y].s==s)
{
g<<a[x].x<<" "<<a[x].y<<" "<<a[x].z<<" "<<a[y].x<<" "<<a[y].y<<" "<<a[y].z<<"\n";
f.close();
g.close();
return 0;
}
else
++x;
g<<"-1\n";
f.close();
g.close();
return 0;
}