Pagini recente » Cod sursa (job #2123240) | Cod sursa (job #1309315) | Cod sursa (job #1834508) | Cod sursa (job #2786258) | Cod sursa (job #3356628)
#include <stdio.h>
#include <unordered_set>
#define D 1
#define MAXN 100
int selection[MAXN];
std::unordered_set<int> trio;
int n, s;
void ReadInput(){
FILE *in;
int i;
in = fopen("loto.in", "r");
fscanf(in, "%d%d", &n, &s);
for(i = 0; i < n; i++)
fscanf(in, "%d", &selection[i]);
fclose(in);
}
void FindTrio(){
FILE *out;
int i, j, k, sp;
for(i = 0; i < n; i++){
for(j = i; j < n; j++){
for(k = j; k < n; k++){
trio.insert(selection[i] + selection[j] + selection[k]);
}
}
}
out = fopen("loto.out", "w");
i = j = k = sp = 0;
while(i < n && (sp == 0)){
if(trio.find(s - (selection[i] + selection[j] + selection[k])) != trio.end()){
sp = selection[i] + selection[j] + selection[k];
fprintf(out, "%d %d %d ", selection[i], selection[j], selection[k]);
}
k++;
if(k == n){
j++;
k = j;
}
if(j == n){
i++;
k = j = i;
}
}
if(sp != 0){
i = 0;
j = 0;
k = 0;
while(i < n && (sp != 0)){
if(s - sp == selection[i] + selection[j] + selection[k]){
sp = 0;
fprintf(out, "%d %d %d ", selection[i], selection[j], selection[k]);
}
k++;
if(k == n){
j++;
k = j;
}
if(j == n){
i++;
k = j = i;
}
}
}else
fprintf(out, "-1");
}
int main(){
ReadInput();
FindTrio();
return 0;
}
/*
3 13
1 2 3
*/