Cod sursa(job #2838757)

Utilizator RobertAcAcatrinei Robert-Marian RobertAc Data 24 ianuarie 2022 16:02:45
Problema Loto Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("loto.in");
ofstream out("loto.out");

struct elem{
    int n;
    int s;
    vector<int> v;
    elem(int val){
        n=1;
        s=val;
        v.push_back(val);
    }
    elem(int val,elem other){
        n=other.n+1;
        s=other.s+val;
        v=other.v;
        v.push_back(val);
    }
};

int main(){
    int n;
    int s;
    in>>n>>s;
    int v[n];
    queue<elem> q;
    for(int i=0;i<n;i++){
        in>>v[i];
        q.push(elem(v[i]));
    }
    while(!q.empty()){
        elem e=q.front();
        q.pop();
        for(int i=1;i<n;i++){
            elem ee=elem(v[i],e);
            if(ee.n==6&&ee.s==s){
                for(auto i:ee.v)out<<i<<' ';
                return 0;
            }
            if(ee.n!=6&&ee.s<s)q.push(ee);
        }
    }
    out<<-1;
}