Pagini recente » Atasamentele paginii inca_inca_vacanta_ix | Cod sursa (job #893095) | Cod sursa (job #470177) | Cod sursa (job #2392772) | Cod sursa (job #1562203)
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int X[1000001], V[101], nodes;
int main() {
int n, s;
// freopen("loto.in", "r", stdin);
// freopen("loto.out", "w", stdout);
cin >> n >> s;
for(int i=1; i<=n; i++)
cin >> V[i];
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
for(int k=1; k<=n; k++) {
X[++nodes] = V[i] + V[j] + V[k];
}
sort(X + 1, X + nodes + 1);
int j = nodes;
for(int i = 1; i <= nodes; i += 1) {
while(X[i] + X[j] > s)
if(--j == 0)
break;
if(j == 0) break;
if(X[i] + X[j] == s) {
int a = X[i], b = X[j];
bool ta = 0, tb = 0;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
for(int k=1; k<=n; k++) {
if(!ta && V[i] + V[j] + V[k] == a) {cout << i << " " << j << " " << k << " "; ta = 1;}
if(!tb && V[i] + V[j] + V[k] == b) {cout << i << " " << j << " " << k << " "; tb = 1;}
}
return 0;
}
}
cout << -1;
return 0;
}