Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct point{
  ll x,y;  
  point operator - (const point &p)const{
    return (point){x-p.x,y-p.y};
  }
  bool operator < (const point &p)const{
    return (y==p.y?x<p.x:y<p.y);
  }
};

ll cross(point a,point b){
  return a.x*b.y-b.x*a.y;
}

ll n;
point t[40];
ll dp[40][40][40][41];
ll pre[40][40][40][41];

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>t[i].x>>t[i].y;
  fill(dp[0],dp[40], 1e9);
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j)continue;
      if(t[j].y<t[i].y)continue;
      dp[i][i][j][2]=0;
    }
  }
  
  for(int si=0;si<n;si++){
    for(int k=2;k+1<=n;k++){
      for(int i=0;i<n;i++){
        if(t[i].y<t[si].y)continue;
        for(int j=0;j<n;j++){
          if(t[j].y<t[si].y)continue;                    
          if(dp[si][i][j][k]==1e9)continue;
            
          for(int to=0;to<n;to++){
            if(t[to].y<t[si].y)continue;
            if(cross(t[j]-t[i],t[to]-t[j])<=0)continue;            
            ll cost = dp[si][i][j][k];
            ll addcost = cross(t[j]-t[si],t[to]-t[si]);            
            if(addcost<=0)continue;
            cost+=addcost;
            if(cost < dp[si][j][to][k+1] ){
              dp[si][j][to][k+1]=cost;              
              pre[si][j][to][k+1]=i;
            }
          }
        }
      }
    }
  }

  int q,a;
  cin>>q;
  while(q--){
    cin>>a;
    int I,J,K;
    ll mini=1e9;
    point g;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        for(int k=0;k<n;k++){
          if(dp[i][j][k][a]>mini)continue;
          if(dp[i][j][k][a]==mini&&g<t[i])continue;
          g=t[i];
          mini=dp[i][j][k][a];
          I=i,J=j,K=k;
        }
      }
    }
    if(mini==1e9){
      cout<<"NA"<<endl;
      continue;
    }
    vector<int> ans;
    for(int i=0;i<a-1;i++){
      ans.push_back(K);
      I=I;
      int tmp=pre[I][J][K][a-i];
      K=J;
      J=tmp;
    }
    ans.push_back(I);
    reverse(ans.begin(),ans.end());
    for(int i=0;i<(int)ans.size();i++){
      if(i)cout<<' ';
      cout<<ans[i]+1;
    }
    cout<<endl;
  }
  return 0;
}

Compiler output:
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:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int (*)[40][41]; _Tp = double; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = long long int (*)[40][41]; _Tp = double]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int (*)[40][41]; _Tp = double]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:27:7:   required from here
   27 |   fill(dp[0],dp[40], 1e9);
      |   ~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const double' to 'long long int [40][41]'
  952 |         *__first = __tmp;
      |         ~~~~~~~~~^~~~~~~