Cod sursa(job #2896315)

Utilizator ggutaGuta George gguta Data 29 aprilie 2022 22:01:10
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
 
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
 
vector<int> a;
unordered_map<int, vector<int>> umap;
 
int n, s_total;
 
int main()
{
    int i, j, k, x, s;
    fin >> n >> s_total;
	
    for (i = 0; i < n; i++)
    {
        fin >> x;
        a.push_back(x);
    }
	
    for(i = 0; i < n; i++)
        for(j = i; j < n; j++)
            for (k = j; k < n; k++)
            {
                s = a[i] + a[j] + a[k];
                umap[s] = { a[i], a[j], a[k] };
				
                if (umap.find(s_total - s) != umap.end())
                {
                    fout << a[i] << " " << a[j] << " " << a[k] << " " << umap[s_total - s][0] << " " << umap[s_total - s][1] << " "<<umap[s_total - s][2];
                    return 0;
                }
 
             }
			 
    fout << -1;
	
    fin.close();
    fout.close();
	
    return 0;
}