Language: C++

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main(){
    ll N;
    cin >> N;
    ll ans=1000;
    ll flg=1;
    ll cnt=0;
    rep(i,0,N) cin >> a[i];
    rep(i,1,N){
        if(a[i] < a[i-1]) flg*=1;
        else flg*=0;
    }
    if(flg==1){cout<<ans<<endl;return 0;}
    
    for(int i=0;i<(1<<N);i++){
        for(int j=0; j<N; j++){
            if(i & (1<<j)){
                cnt = (ans/a[j]);
                ans -= ((ans/a[j])*a[j]);
            }
            else if(i & (0<<j)){
                ans += ((cnt)*a[j]);
            }
        }
        ans=max(ans,1000);
    }

    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:23: error: 'a' was not declared in this scope
   21 |     rep(i,0,N) cin >> a[i];
      |                       ^
a.cc:23:12: error: 'a' was not declared in this scope
   23 |         if(a[i] < a[i-1]) flg*=1;
      |            ^
a.cc:31:28: error: 'a' was not declared in this scope
   31 |                 cnt = (ans/a[j]);
      |                            ^
a.cc:35:31: error: 'a' was not declared in this scope
   35 |                 ans += ((cnt)*a[j]);
      |                               ^
a.cc:38:16: error: no matching function for call to 'max(ll&, int)'
   38 |         ans=max(ans,1000);
      |             ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:38:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   38 |         ans=max(ans,1000);
      |             ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:38:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   38 |         ans=max(ans,1000);
      |             ~~~^~~~~~~~~~