Pagini recente » Cod sursa (job #269506) | Istoria paginii runda/oji_go_11_12 | Cod sursa (job #623231) | Cod sursa (job #282163) | Cod sursa (job #1562211)
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cassert>
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=i; j<=n; j++)
for(int k=j; 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=i; j<=n; j++)
for(int k=j; k<=n; k++) {
if(!ta && V[i] + V[j] + V[k] == a) {cout << i << " " << j << " " << k; ta = 1; if(tb == 0) cout << " ";}
if(!tb && V[i] + V[j] + V[k] == b) {cout << i << " " << j << " " << k; tb = 1; if(ta == 0) cout << " ";}
}
assert((ta & tb) == 1);
return 0;
}
}
cout << -1;
return 0;
}