Cod sursa(job #2732731)

Utilizator realmeabefirhuja petru realmeabefir Data 29 martie 2021 11:09:01
Problema Loto Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

ifstream f ("loto.in");
ofstream g ("loto.out");

unordered_map<int,pair<int,int>> dic;
int v[100];

int main()
{
    int n, s;
    f >> n >> s;
    for (int i = 0; i < n; i++)
        f >> v[i];

    for (int i = 0; i < n;i ++)
        for (int j = 0; j < n; j++)
            dic[v[i]+v[j]] = {v[i],v[j]};



    for (auto p1: dic)
        for (auto p2:dic){
            auto test = dic[s-p1.first - p2.first];
            if (test.first != 0) {
                g << p1.second.first << ' ' <<  p1.second.second << ' '  << p2.second.first << ' ' << p2.second.second  << ' ' << test.first << ' ' << test.second;
                return 0;
            }
        }



    g << -1;

    return 0;
}