Cod sursa(job #2260701)

Utilizator nicolaefilatNicolae Filat nicolaefilat Data 15 octombrie 2018 14:12:59
Problema Loto Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <iostream>
#include <fstream>
#include <map>
#include <vector>

const int MAXN = 100 + 5;

using namespace std;

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

int n,v[MAXN],sum;
map<int,bool>exista;
map<int,pair<int,pair<int,int> > >mapa;
int main()
{
    in>>n>>sum;
    for(int i = 1; i <= n; i++)
        in>>v[i];
    int s;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                s = v[i] + v[j] + v[k];
                if(!exista[s]){
                    exista[s] = true;
                    mapa[s].first = v[i];
                    mapa[s].second.first = v[j];
                    mapa[s].second.second = v[k];
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                s = v[i] + v[j] + v[k];
                if(exista[sum - s]){
                    s = sum - s;
                    out<<mapa[s].first<<" "<<mapa[s].second.first<<" "<<mapa[s].second.second<<" "<<v[i]<<" "<<v[j]<<" "<<v[k];
                    return 0;
                }
            }
        }
    }
    out<<-1;
    return 0;
}