Cod sursa(job #2621667)

Utilizator anamaria2602Avram Ana Maria anamaria2602 Data 30 mai 2020 16:31:35
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <fstream>
#define MAXX 101

using namespace std;

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

    f >> N >> Sum;
    for(i=1; i<=N; i++)
        f >> V[i];
    for(int i=1; i<=N; i++)
        for(int j=1; j<=N; j++)
            for(int l=1; l<=N; l++)
            {
                Bilet[++k].unu = i;
                Bilet[k].doi = j;
                Bilet[k].trei = l;
                Bilet[k].suma = i + j + 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;
}