Cod sursa(job #3239225)

Utilizator Bianca2507Negret Bianca Bianca2507 Data 3 august 2024 10:12:41
Problema Loto Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("loto.in");
ofstream cout("loto.out");
int n,s,v[105];
int main()
{
    cin>>n>>s;
    for(int i=1; i<=n; i++)
        cin>>v[i];
    sort(v+1,v+n+1);
    for(int i1=1; i1<=n; i1++)
        for(int i2=1; i2<=n; i2++)
            for(int i3=1; i3<=n; i3++)
                for(int i4=1; i4<=n; i4++)
                    for(int i5=1; i5<=n; i5++)
                    {
                        int aux=s-v[i1]-v[i2]-v[i3]-v[i4]-v[i5];
                        int st=1,dr=n;
                        while(st<=dr)
                        {
                            int mid=(st+dr)/2;
                            if(v[mid]==aux)
                            {
                                cout<<v[i1]<<" "<<v[i2]<<" "<<v[i3]<<" "<<v[i4]<<" "<<v[i5]<<" "<<v[mid];
                                return 0;
                            }
                            else if(v[mid]>aux)
                                dr=mid-1;
                            else
                                st=mid+1;
                        }
                    }
    cout<<-1;
    return 0;
}