Cod sursa(job #1799258)

Utilizator martonsSoos Marton martons Data 5 noiembrie 2016 23:21:38
Problema Loto Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <unordered_map>

using namespace std;

struct comb{
    int a, b, c;
};

int main()
{
    ios::sync_with_stdio(false);
    ifstream in("loto.in");
    int n, s, v[100];
    unordered_map<int, comb> m;

    in>>n>>s;
    for(int i=0;i<n;i++){
        in>>v[i];
    }

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

    ofstream out("loto.out");
    unordered_map<int, comb>::iterator it;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                if((it = m.find(s-(v[i]+v[j]+v[k])))!=m.end()){
                    out<<v[i]<<" "<<v[j]<<" "<<v[k]<<" "<<it->second.a<<" "<<it->second.b<<" "<<it->second.c;
                    return 0;
                }
            }
        }
    }
    out<<-1;
    return 0;
}