Cod sursa(job #811628)

Utilizator UnforgivenMihai Catalin Botezatu Unforgiven Data 12 noiembrie 2012 19:05:26
Problema Loto Scor 65
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

vector <long> a;
bool myfunction (int i,int j) { return (i>j); }

int main()
{
    ifstream input("loto.in");
    ofstream output("loto.out");
    long s;
    int n;
    input >> n >> s;
    for (int i=0;i<n;i++)
    {
        long x;
        input >> x;
        a.push_back(x);
    }
    sort(a.begin(),a.end(),myfunction);

    int stop = 1;
    int i,x,y,z,k,m;
    for (i=0;i<n&&stop&&a[i]*6>=s;i++)
    for (x=i;x<n&&stop&&a[i]+a[x]*5>=s&&a[i]+a[n-1]*5<=s;x++)
    for (y=x;y<n&&stop&&a[i]+a[x]+a[y]*4>=s&&a[i]+a[x]+a[n-1]*4<=s;y++)
    for (z=y;z<n&&stop&&a[i]+a[x]+a[y]+a[z]*3>=s&&a[i]+a[x]+a[y]+a[n-1]*3<=s;z++)
    for (k=z;k<n&&stop&&a[i]+a[x]+a[y]+a[z]+a[k]*2>=s&&a[i]+a[x]+a[y]+a[z]+a[n-1]*2<=s;k++)
    for (m=k;m<n&&stop&&a[i]+a[x]+a[y]+a[z]+a[k]+a[m]>=s;m++)
    if (a[i]+a[x]+a[y]+a[z]+a[k]+a[m] == s)
    {
        output << a[i]<< " "<<a[x]<<" "<<a[y]<<" "<<a[z]<<" "<<a[k]<<" "<<a[m];
        stop = 0;
    }
    if (stop) output << -1;
    input.close();
    output.close();
    return 0;
}