Pagini recente » Cod sursa (job #477977) | Cod sursa (job #2477552) | Cod sursa (job #1286323) | Cod sursa (job #2964214) | Cod sursa (job #1562131)
#include <bits/stdc++.h>
using namespace std;
FILE*f=fopen("loto.in","r"),*g=fopen("loto.out","w");
int n, s;
int V[105], N[1000009][4];
pair <int, int> X[1000009];
void afisare(int x, int y)
{
fprintf(g, "%d %d %d %d %d %d", N[X[x].second][1], N[X[x].second][2], N[X[x].second][3], N[X[y].second][1], N[X[y].second][2], N[X[y].second][3]);
}
int main()
{
fscanf(f, "%d %d", &n, &s);
for(int i = 1; i <= n; i++)
{
fscanf(f, "%d", &V[i]);
}
int nr = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
for(int k = 1; k <= n; k++)
{
nr++;
X[nr].first = V[i]+V[j]+V[k];
X[nr].second = nr;
N[nr][1] = i;
N[nr][2] = j;
N[nr][3] = k;
}
sort(X+1, X+nr+1);
int p = 1, u = nr;
while(p <= u)
{
if(X[p].first + X[u].first == s)
{
afisare(p, u);
return 0;
}
if(X[p].first + X[u].first > s)
u--;
if(X[p].first + X[u].first < s)
p++;
}
fprintf(g,"-1");
return 0;
}