Cod sursa(job #1604791)

Utilizator LuurAndrei Florea Luur Data 18 februarie 2016 16:36:33
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include<fstream>
#include<map>
#define Tmax 101
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
struct myType{
    int a , b, c;
};
map<long, myType> m;
map<long, myType>::iterator f;
long N, S, a[Tmax];
bool t = 1;
int main(){
    in>>N>>S;
    for(int i = 1; i<= N; i++){
        in>>a[i];
    }
    for(int i = 1; i <= N; i++){
        for(int j = i; j <= N; j++){
            for(int k = j; k <= N; k++){
                long s = a[i] + a[j] + a[k];
                if(s <= S){
                    myType x = {a[i], a[j], a[k]};
                    m.insert(make_pair(s, x));
                }
            }
        }
    }
    for(int i = 1; i <= N && t; i++){
        for(int j = i; j <= N && t; j++){
            for(int k = j; k <= N && t; k++){
                long s = S- a[i] - a[j] - a[k];
                if (s >= 0){
                    f = m.find(s);
                    if (f != m.end()){ t = 0;
                        myType x = f->second;
                        out<<a[i]<<' '<<a[j]<<' '<<a[k]<<' '<<x.a<<' '<<x.b<<' '<<x.c<<'\n';
                    }
                }
            }
        }
    }
    if (t) out<<-1<<'\n';
    return 0;
}