Pagini recente » Cod sursa (job #287836) | Istoria paginii runda/and/clasament | Istoria paginii runda/oji_simulare_02/clasament | Cod sursa (job #405797) | Cod sursa (job #1598189)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int N;
long S, A[101];
struct DTA{
int a, b, c;
long s;
bool operator < (const DTA & i) const{
return s < i.s;
}
};
typedef vector<DTA> DV;
DV V;
bool cmp(long x, long y){
return x < y;
}
int BiSCh(DV V, int x) {
int i, ps, N = V.size();
for (ps = 1; ps < N; ps <<= 1);
for (i = 0; ps; ps >>= 1)
if (i + ps < N && V[i + ps].s <= x) i += ps;
if (V[i].s == x) return i;
else return -1;
}
int main(){
FILE *in = fopen("loto.in", "r");
FILE *out = fopen("loto.out", "w");
fscanf(in, "%d%ld", &N, &S);
for( int i = 1; i <= N ; ++i){
fscanf(in, "%ld",&A[i]);
}
for(int i = 1; i <= N; ++i){
for(int j = 1; j <= N; ++j){
for(int k = 1; k <= N; ++k){
DTA T; T.a = i; T.b = j; T.c = k; T.s = A[i]+A[j]+A[k];
V.push_back(T);
}
}
}
sort(V.begin(), V.end());
bool t = 1;
for(int i = 1; i <= N && t; ++i){
for(int j = 1; j <= N && t; ++j){
for(int k = 1; k <= N && t; k++){
long FND = S - A[i]-A[j]-A[k];
long EX = BiSCh(V, FND);
if (V[EX].s == FND){
t = 0;
fprintf(out,"%ld %ld %ld %ld %ld %ld",A[i], A[j], A[k], A[V[EX].a], A[V[EX].b], A[V[EX].c]);
}
}
}
}
if (t) fprintf(out,"-1");
return 0;
}