Cod sursa(job #1743762)

Utilizator stefanik_robertzRobert S stefanik_robertz Data 18 august 2016 17:54:02
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <fstream>
#include <iostream>
#include <set>
struct h{
    int a,b;
};
using namespace std;
h comb[100000000];
long v[100],n,s,cnt;
set<long>a;
set<long>::iterator it1,it2;
ifstream f("loto.in");
ofstream g("loto.out");
void citire(){
    f>>n>>s;
    for(int i=0;i<n;i++)
    {
        f>>v[i];
    }
    f.close();
}
bool ok;
void make_set(){
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            a.insert(v[i]+v[j]);
            comb[cnt].a=v[i];
            comb[cnt++].b=v[j];
        }
    }
}
void afisare(){
    long a=*it1,b=*it2,c=s-*it1-*it2;
    for(int i=0;i<cnt;i++){
        if(comb[i].a+comb[i].b==a){a=-1;g<<comb[i].a<<" "<<comb[i].b<<" ";}
        if(comb[i].a+comb[i].b==b){b=-1;g<<comb[i].a<<" "<<comb[i].b<<" ";}
        if(comb[i].a+comb[i].b==c){c=-1;g<<comb[i].a<<" "<<comb[i].b<<" ";}
    }
    ok=true;
}
void fun(){
    for(it1=a.begin();it1!=a.end();it1++){
        for(it2=it1;it2!=a.end();it2++){
            if(a.find(s-*it1-*it2)!=a.end()++){
                afisare();
                return;
            }
        }
    }
}
int main(){
    citire();
    make_set();
    int nr=*a.end()--;
    if(3*nr>=s)fun();
    if(!ok)g<<-1;
}