1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>

int main(){
    int k;
    long long int n;
    scanf("%d %lld",&k,&n);
    int p[k];
    for(int i=0;i<k;i++) scanf("%d",&p[i]);
    std::priority_queue<long long int> Q;
    Q.push(1);
    long long int best = 1;
    bool isEqual = false;
    while(!Q.empty()){
        long long int el = Q.top();
        Q.pop();
        for(int i=0;i<k;i++){
            long long int tmp = el*p[i];
            if(tmp<n){
                Q.push(tmp);
                best = std::max(best,tmp);
            }
            if(tmp==n){
                isEqual=true;
                best = n;
                break;
            }
        }
        if(isEqual){
            break;
        }
    }
    printf("%lld\n",best);
}

//Author: Helena Borak