Pagini recente » Cod sursa (job #1604343) | Cod sursa (job #655556) | Cod sursa (job #682033) | Cod sursa (job #2961077) | Cod sursa (job #1603208)
#include <cstdio>
#include <vector>
#include <algorithm>
#include <fstream>
#define DMAX 1000100
#define TMAX 101
#define K 393241
using namespace std;
typedef long ll;
ifstream in("loto.in");
ofstream out("loto.out");
int n;
long S, a[TMAX], m;
bool t = 1;
struct myType{
int a, b, c;
ll s;
bool operator < (myType const & x) const{
return s < x.s;
}
};
typedef vector<myType> vm;
vm v[K];
bool sortOp(myType x, myType y){
return x.s < y.s;
}
inline ll h(ll x){
return x % K;
}
inline myType Find(ll x){
ll y = h(x);
bool t = 1;
myType T; T.s = -1;
for(unsigned int i = 0; i < v[y].size() && t; i++){
T = v[y][i];
if (T.s == x) t = 0;
}
return T;
}
int main(){
in >> n >> S;
for(int i = 1; i <= n; i++){
in >> a[i];
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
for(int k = 1; k <= n; k++){
long long STemp = a[i] + a[j] + a[k];
if (STemp <= S){
myType T;
T.a = a[i]; T.b = a[j]; T.c = a[k]; T.s = STemp;
v[h(STemp)].push_back(T);
}
}
}
}
for(int i = 1; i <= n && t; i++){
for(int j = 1; j <= n && t; j++){
for(int k = 1; k <= n && t; k++){
ll c = S - a[i]-a[j]-a[k];
if (c >= 0){
myType it = Find(c);
if (it.s != -1){
out <<a[i]<<' '<<a[j]<<' '<<a[k]<<' '<<it.a<<' '<<it.b<<' '<<it.c<<'\n';
t = 0;
}
}
}
}
}
if (t) out <<-1<<'\n';
return 0;
}