Pagini recente » Cod sursa (job #581946) | Cod sursa (job #2391684) | Cod sursa (job #2685944) | Cod sursa (job #2320943) | Cod sursa (job #943818)
Cod sursa(job #943818)
#include<fstream>
#include<vector>
using namespace std;
const int kmod = 666019;
class obj{
public:
int x, y, z, key, sum;
obj(){};
obj(int x1, int y1, int z1){
x = x1;
y = y1;
z = z1;
key = (x + y + z) % kmod;
sum = x + y + z;
}
};
vector<obj> h[kmod];
int isthere(int key){
if(key < 0)
return 0;
int k = key % kmod;
for(int i = 0; i < h[k].size(); ++i)
if(h[k][i].sum == key)
return i + 1;
return 0;
}
void add(obj A){
h[A.key].push_back(A);
}
int main(){
ifstream in("loto.in");
ofstream out("loto.out");
int n, s;
in >> n >> s;
int a[105];
for(int i = 1; i <= n; ++i)
in >> a[i];
for(int i = 1; i <= n; ++i)
for(int j = i; j <= n; ++j)
for(int k = j; k <= n; ++k){
obj t(a[i], a[j], a[k]);
int key, p = (s - t.key) % kmod;
if(key = isthere(s - t.key)){
--key;
out << t.x << " " << t.y << " " << t.z << " " << h[p][key].x << " " << h[p][key].y << " " << h[p][key].z;
return 0;
}
else
add(t);
}
out << "-1";
return 0;
}