Pagini recente » Cod sursa (job #295906) | Cod sursa (job #2982589) | Cod sursa (job #1767175) | Cod sursa (job #3213575) | Cod sursa (job #196117)
Cod sursa(job #196117)
#include <cstdio>
#include <algorithm>
#include <vector>
#define Nmax 102
using namespace std;
long N,S,a[Nmax];
typedef struct {
long x,y,z,s;
}type;
type c[Nmax*Nmax*Nmax];
struct cmp{
bool operator () (const type &a, const type &b) const {
if (a.s < b.s) return 1;
return 0;
}
};
int main(){
FILE *f = fopen("loto.in","r");
FILE *g = fopen("loto.out","w");
int i,j,k;
fscanf (f,"%ld %ld", &N, &S);
for (i = 1; i <= N; ++i)
fscanf (f,"%ld", a+i);
fclose(f);
int nd = 0;
for (i=1;i<=N;++i)
for (j=1;j<=N;++j)
for (k=1;k<=N;++k){
++nd;
c[nd].s=a[i]+a[j]+a[k],
c[nd].x=a[i],
c[nd].y=a[j],
c[nd].z=a[k];
}
sort (c+1,c+nd+1,cmp());
for (i=1;i<=nd;++i)
if (c[i].s<=S-c[i].s){
int li = i; int lf = nd;
int m;
while (li<=lf){
m = (li+lf) >> 1;
if (c[m].s==S-c[i].s) break;
if (c[m].s<S-c[i].s) li=m+1;
else lf=m-1;
}
if (c[m].s == S-c[i].s){
fprintf (g,"%ld %ld %ld %ld %ld %ld", c[m].x, c[m].y, c[m].z, c[i].x, c[i].y, c[i].z);
fclose(g);
return 0;
}
}
fprintf (g,"-1\n");
fclose(g);
return 0;
}