Cod sursa(job #1541690)

Utilizator darkseekerBoaca Cosmin darkseeker Data 4 decembrie 2015 14:58:36
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <vector>
#include <iostream>
#include <unordered_map>
#include <tuple>
#include <fstream>
using namespace std;

int main() {
#ifdef INFOARENA
    ifstream cin("loto.in");
    ofstream cout("loto.out");
#endif
    int N, S;
    vector<int> numbers;

    cin >> N >> S;
    numbers.resize(N);
    for (int i = 0; i < N; ++i) {
      cin >> numbers[i];
    }

    unordered_map<int, tuple<int, int, int>> m;

    for (auto n1 = numbers.begin(); n1 != numbers.end(); ++n1) {
      for (auto n2 = n1; n2 != numbers.end(); ++n2) {
        for (auto n3 = n2; n3 != numbers.end(); ++n3) {
            m[*n1 + *n2 + *n3] = make_tuple(*n1, *n2, *n3);
        }
      }
    }

    for (auto n1 = numbers.begin(); n1 != numbers.end(); ++n1) {
      for (auto n2 = n1; n2 != numbers.end(); ++n2) {
        for (auto n3 = n2; n3 != numbers.end(); ++n3) {
          auto it = m.find(S - (*n1 + *n2 + *n3));
          if (it != m.end()) {
            auto tup = it->second;
            cout << get<0>(tup) << ' ' << get<1>(tup) << ' ' << get<2>(tup) << ' '
              << *n1 << ' ' << *n2 << ' ' << *n3 << endl;
            return 0;
          }
        }
      }
    }

    cout << -1 << endl;
    return 0;
}