Cod sursa(job #2611177)

Utilizator Stefan_RaduStefan Radu Stefan_Radu Data 6 mai 2020 15:33:37
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.65 kb
// By Stefan Radu

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <map>

using namespace std;

ifstream cin("loto.in");
ofstream cout("loto.out");

#define sz(x) (int)(x).size()

typedef pair < int, int > pii;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

struct Elem {
  int s, a, b, c;
};

const int MOD = 786433;	
vector < vector < Elem > > hashMap(MOD);
 
bool hFind(int s) {
  return hashMap[s % MOD].size() != 0;
}
 
void hInsert(Elem el) {
  if (hFind(el.s)) return;
  hashMap[el.s % MOD].emplace_back(el);
}

int main() {

#ifdef STEF
  freopen("input", "r", stdin);
  freopen("output", "w", stdout);
#endif

  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int n, ss; cin >> n >> ss;
  vector < int > v(n);
  for (int i = 0; i < n; ++ i) {
    cin >> v[i];
  }

  for (int i = 0; i < n; ++ i)
  for (int j = 0; j < n; ++ j)
  for (int k = 0; k < n; ++ k)
    hInsert({v[i] + v[j] + v[k], v[i], v[j], v[k]});

  int a = -1, b = -1;
  for (const auto &v : hashMap) {
    for (const auto &x : v) {
      if (hFind(ss - x.s)) {
        a = x.s;
        b = ss - x.s;
        break;
      }
    }
    if (a != -1) break;
  }

  if (a == -1) {
    cout << -1 << '\n';
    return 0;
  }

  return 0;

  auto& el = hashMap[a % MOD][0];
  cout << el.a << ' ' << el.b << ' ' << el.c << ' ';
  el = hashMap[b % MOD][0];
  cout << el.a << ' ' << el.b << ' ' << el.c << '\n';
}