Cod sursa(job #3216531)

Utilizator vladsoartavlad sofronea vladsoarta Data 17 martie 2024 18:05:50
Problema Loto Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream cin("loto.in");
ofstream cout("loto.out");

int s,n,i,v[101];
struct vladut{
    int a,b,c;
};

vector<vladut>meet;

bool cmp(vladut a,vladut b)
{
    return a.a+a.b+a.c<b.a+b.b+b.c;
}

int main()
{
    cin>>n>>s;
    for(i=1; i<=n; i++)
        cin>>v[i];
    meet.push_back({0,0,0});
    for(i=1; i<=n; i++)
        for(int j=i; j<=n; j++)
            for(int h=j; h<=n; h++)
                meet.push_back({v[i],v[j],v[h]});
    sort(meet.begin(),meet.end(),cmp);
    for(i=1;i<meet.size();i++)
        cout<<meet[i].a<<" "<<meet[i].b<<" "<<meet[i].c<<'\n';
    int st=1,dr=1;
    while(dr>=st)
    {
        while(s-(meet[st].a+meet[st].b+meet[st].c+meet[dr].a+meet[dr].b+meet[dr].c)>0&&dr<meet.size()-1)
            dr++;
        if(s-(meet[st].a+meet[st].b+meet[st].c+meet[dr].a+meet[dr].b+meet[dr].c)==0)
        {int rsp[7]={meet[st].a,meet[st].b,meet[st].c,meet[dr].a,meet[dr].b,meet[dr].c};
            sort(rsp,rsp+5);
            for(i=0;i<=5;i++)
                cout<<rsp[i]<<" ";
        return 0;
        }
        else
            st++;

    }
    cout<<-1;
    return 0;
}