この問題は順列全列挙を問います。
問題から がランダムな順番で言い渡されると書いてあるので、単に の順で計算するとは限りません。
このランダムな順番は、最悪 通り存在します( はすべて相異なると仮定する時)。制約から であるため、 通りを全列挙することが適切です。
そのうち 番目を撃ち落とせなかったと書かれていますが、これは言い換えれば 以上 以下の整数からなる順列 を並び替えた数列 に対し、 として計算することを表しています。この挙動を実装できると、正解することができます。
以上から で実装することが可能です。以下は解答例になります(C++)。
C++
xxxxxxxxxx
//[0,n)
//[a,b)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
using pq = priority_queue<ll,vector<ll>,greater<ll>>;
const ll inf = 8e18;
const int iinf = (int)1e9;
const int mod9 = 998244353;
const int mod1 = 1000000007;
struct Edge { int to; ll cost; int from; };
bool compe(const Edge &e,const Edge &e2){ return e.cost < e2.cost; }
using Graph = vector<vector<int>>;
using EGraph = vector<Edge>;
using SGraph = vector<set<ll>>;
template <typename T>
int siz(T& a){ return (int)a.size(); }
using namespace std;
int main(){
int n,m; cin >> n >> m;
vector<int> A(n);
set<int> B;
rep(i,n) cin >> A[i];
rep(i,m){
int b; cin >> b;
B.insert(b);
}
set<int> st;
sort(all(A));
do {
int res = 0;
rep(i,n) if(!B.count(i)) res += A[i];
st.insert(res);
} while(pmt(all(A)));
cout << siz(st);
}
Python
xxxxxxxxxx
import itertools
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
if m == 0:
print(1)
exit()
B = list(map(int,input().split()))
st = set()
for v in itertools.permutations(A):
t = 0
for i in range(n):
if i+1 in B: continue
t += v[i]
st.add(t)
print(len(st))