Cod sursa(job #3238056)

Utilizator SPetruSolom Petru SPetru Data 16 iulie 2024 14:35:15
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <unordered_map>

using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

int n, s, a[101];

struct Triplet{
  int x, y, z;
};

unordered_map <int, Triplet> sum;

int main(){
  fin >> n >> s;
  for(int i = 1; i <= n; i++)
    fin >> a[i];

  for(int i = 1; i <= n; i++){
    for(int j = i; j <= n; j++){
      for(int k = j; k <= n; k++){
        sum[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};
      }
    }
  }
  
  for(int i = 1; i <= n; i++){
    for(int j = i; j <= n; j++){
      for(int k = j; k <= n; k++){
        int dif = s - a[i] - a[j] - a[k];
        if(sum.count(dif)){
          Triplet t = sum[dif];
          fout << a[i] << ' ' << a[j] << ' ' << a[k] << ' ' << t.x << ' ' << t.y << ' ' << t.z;
          return 0;
        }
      }
    }
  }
  fout << -1;
  return 0;
}