Pagini recente » Cod sursa (job #108701) | Cod sursa (job #2445498) | Cod sursa (job #372376) | Cod sursa (job #2899106) | Cod sursa (job #1680202)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define MOD 67777
using namespace std;
struct rez {
int a;
int b;
int c;
int Su;
bool E;
};
ifstream in("loto.in");
ofstream out("loto.out");
int v[102];
vector<rez> sum[MOD];
rez temp;
vector<rez>::iterator it;
int main() {
int n,S;
in >> n >> S;
for(int i = 1; i <= n; i++)
in >> v[i];
sort(v+1, v+n+1);
for(int a = 1; a <= n; a++) {
if(v[a] > S)
break;
for(int b = 1; b <= n; b++) {
if(v[a]+v[b] > S)
break;
for(int c = 1; c <= n; c++) {
if(v[a]+v[b]+v[c] > S)
break;
temp.a = a;
temp.b = b;
temp.c = c;
temp.Su = v[a]+v[b]+v[c];
temp.E = true;
sum[(v[a]+v[b]+v[c])%MOD].push_back(temp);
}
}
}
for(int d = 1; d <= n; d++) {
if(v[d] > S)
break;
for(int e = 1; e <= n; e++) {
if(v[d]+v[e] > S)
break;
for(int f = 1; f <= n; f++) {
if(v[d]+v[e]+v[f] > S)
break;
if(sum[(S-v[d]-v[e]-v[f])%MOD].size() != 0) {
for(it = sum[(S-v[d]-v[e]-v[f])%MOD].begin(); it != sum[(S-v[d]-v[e]-v[f])%MOD].end(); it++) {
if(S-v[d]-v[e]-v[f] == it->Su) {
temp = *it;
out << v[d] << " " << v[e] << " " << v[f] << " " << v[temp.c] << " " << v[temp.b] << " " << v[temp.a] << '\n';
return 0;
}
}
}
}
}
}
out << "-1" << '\n';
return 0;
}