Cod sursa(job #943818)

Utilizator AnonymouslegionAnonymous Anonymouslegion Data 26 aprilie 2013 15:46:01
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#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;
}