Cod sursa(job #3176118)

Utilizator VladNANegoita Vlad-Andrei VladNA Data 26 noiembrie 2023 18:49:12
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,avx,fma,avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

struct solution {
  int sum;
  int i, j, k;
};

bool operator<(const solution &sol, const solution &other) {
  return sol.sum < other.sum;
}
bool operator==(const solution &sol, const solution &other) {
  return sol.sum == other.sum;
}

void solve() {
  int n, s;
  cin >> n >> s;

  vector<int> v(n);
  for (int &x : v)
    cin >> x;

  set<solution> sum3;
  for (int i = 0; i < n; ++i)
    for (int j = i; j < n; ++j)
      for (int k = j; k < n; ++k)
        sum3.insert({v[i] + v[j] + v[k], i, j, k});

  for (auto [sum, i, j, k] : sum3) {
    auto it = sum3.find({s - sum, 0, 0, 0});
    if (it == sum3.end())
      continue;

    vector<int> sol{v[i], v[j], v[k], v[it->i], v[it->j], v[it->k]};
    sort(sol.begin(), sol.end());

    for (int x : sol)
      cout << x << ' ';
    cout << endl;

    return;
  }

  cout << -1 << endl;
}

int main() {
  freopen("loto.in", "r", stdin);
  freopen("loto.out", "w", stdout);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();

  return 0;
}