Cod sursa(job #2623559)

Utilizator anamaria2602Avram Ana Maria anamaria2602 Data 3 iunie 2020 13:40:53
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <fstream>
#define MAXX 1000005
#define MAXX1 1001
#define MAXX2 20
using namespace std;

ifstream f("loto.in");
ofstream g("loto.out");
struct loto
{
    long  unu,doi,trei,suma;
} Bilet[MAXX];
int amax,N,i,k,V[MAXX1],A[MAXX2];
long Sum;
int main()
{

    f >> N >> Sum;
    for(i=1; i<=N; i++)
        f >> V[i];
    for(int i=1; i<=N; i++)
        for(int j=i; j<=N; j++)
            for(int l=j; l<=N; l++)
            {
                Bilet[++k].unu = V[i];
                Bilet[k].doi = V[j];
                Bilet[k].trei = V[l];
                Bilet[k].suma = V[i] + V[j] + V[l];
            }
    int st = 1;
    int dr = k;
    while(st!=dr)
    {
        if(Bilet[st].suma+Bilet[dr].suma<Sum)
            st++;
        else if(Bilet[st].suma+Bilet[dr].suma>Sum)
            dr--;
        else if(Bilet[st].suma+Bilet[dr].suma==Sum)
        {
            A[1] = Bilet[st].unu;
            A[2] = Bilet[st].doi;
            A[3] = Bilet[st].trei;
            A[4] = Bilet[dr].unu;
            A[5] = Bilet[dr].doi;
            A[6] = Bilet[dr].trei;
            sort(A+1,A+7);
            for(int i=1;i<=6;i++)
                g << A[i] << " ";
            return 0;
        }
    }
    g << "-1";

    return 0;
}