Cod sursa(job #2957437)

Utilizator nicu_ducalNicu Ducal nicu_ducal Data 22 decembrie 2022 16:41:54
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <bits/stdc++.h>
using namespace std;

template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template <typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
using i64 = long long int;

const int INF = INT_MAX, MOD = 1e9 + 7;
const long long LINF = LLONG_MAX;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {0, 0, 0, -1, 1, -1, 1, 1, -1};
const int dy[] = {0, -1, 1, 0, 0, -1, 1, -1, 1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

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

  int N;
  cin >> N;
  i64 S;
  cin >> S;
  vector<i64> nums(N);
  for (int i = 0; i < N; i++)
    cin >> nums[i];

  map<i64, pair<i64, i64>> sums;
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      for (int k = j; k < N; k++) {
        if (nums[i] + nums[j] + nums[k] <= S)
          sums[nums[i] + nums[j] + nums[k]] = {nums[i], nums[j]};
      }
    }
  }

  vector<i64> ans;
  for (auto &[sum, pair]: sums) {
    if (sums.find(S - sum) != sums.end()) {
      cout << pair.first << " " << pair.second << " " << sum - pair.first - pair.second << " ";
      auto &other_pair = sums[S - sum];
      cout << other_pair.first << " " << other_pair.second << " " << S - sum - other_pair.first - other_pair.second << "\n";
      return 0;
    }
  }

  cout << -1 << "\n";

  return 0;
}