Pagini recente » Cod sursa (job #2732378) | Cod sursa (job #2760122) | Cod sursa (job #642513) | Istoria paginii runda/oni17_11_12_z1/clasament | Cod sursa (job #1562193)
#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];
}
long long sol = 0;
sort(X + 1, X + nodes + 1);
int j = nodes;
for(int i = 1; i <= nodes; i += 1) {
while(X[i] + X[j] > s) j--;
if(X[i] + X[j] == s) {
int a = i, b = 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] == X[a]) {cout << i << " " << j << " " << k << " "; ta = 1;}
else if(!tb && V[i] + V[j] + V[k] == X[b]) {cout << i << " " << j << " " << k << " "; tb = 1;}
}
return 0;
}
}
cout << -1;
return 0;
}