Cod sursa(job #2747495)

Utilizator mvoineaVoinea Mihai-Alexandru mvoinea Data 29 aprilie 2021 11:48:47
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

ifstream input("loto.in");
ofstream output("loto.out");

int main() {
  int n, s;
  input >> n >> s;
  vector<int> nr;
  for (int i = 0; i < n; ++i) {
    int aux;
    input >> aux;
    nr.push_back(aux);
  }

  unordered_map<int,vector<int> > sums;
  for (int i = 0; i < nr.size(); ++i) {
    for (int j = i; j < nr.size(); ++j) {
      for (int k = j; k < nr.size(); ++k) {
        int aux;

        aux = nr[i] + nr[j] + nr[k];
        sums[aux] = {nr[i], nr[j], nr[k]};

        if(sums.find( s - aux ) != sums.end()) {
          output << nr[i] << " " << nr[j] << " " << nr[k] << " ";
          output << sums[s - aux][0] << " " << sums[s - aux][1] << " " << sums[s - aux][2];
          return 0;
        }
      }
    }
  }
  output << -1;
  return 0;
}