Pagini recente » Monitorul de evaluare | Diferente pentru calibrare-limite-de-timp intre reviziile 213 si 221 | Istoria paginii utilizator/latif371 | Diferente pentru calibrare-limite-de-timp intre reviziile 184 si 221 | Cod sursa (job #1604791)
#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;
}