Cod sursa(job #1238274)

Utilizator dica69Alexandru Lincan dica69 Data 6 octombrie 2014 12:24:24
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");

int a[100], x, n;

int main()
{
    f >> x >> n;
    for (int i = 1; i <= x; i++)
    {
        f >> a[i];
    }
    for (int i = 1; i <= x; i++)
        for (int j = 1; j <= x; j++)
            if (a[i] < a[j])
            {
                int temp = a[j];
                a[j] = a[i];
                a[i] = temp;
            }
    int S = 0;
    int l = 0;
    while (S < n)
    {
        if (x <= 0) break;
        int t = S + a[x];
        if (t > n) x = x - 1;
        else
        {
            l = 1;
            g << a[x] << " ";
            S = t;
        }
        cout << S << endl;
    }
    if (l == 0) g << "-1";
}