Macw07的商品纪念铺题解
2023-08-09 09:20:02
发布于:浙江
#include<bits/stdc++.h>
using namespace std;
int main(){
freopen("buy.in" ,"r" ,stdin);
freopen("buy.out" ,"w" ,stdout);
int n ,k ,things[5001] = {} ,s_acgo = 0 ,b_acgo = 0;
cin >> n >> k;
for (int i = 1 ; i <= n ; i++)
cin >> things[i];
for (int i = 1 ; i <= k ; i++){
int d_idx[5001] = {} ,idx = 0 ,sum = 0 ,_k = 0;
cin >> s_acgo;
for (int j = 1 ; j <= s_acgo ; j++){
cin >> b_acgo;
sum += things[b_acgo];
idx++;
d_idx[idx] = b_acgo;
}
for (int j = 1 ; j <= idx ; j++){
for (int _k_ = d_idx[j] ; _k_ <= n ; _k_++){
swap(things[_k_ - _k] , things[_k_ - _k + 1]);
}
_k += 1;
}
cout << sum << " ";
}
fclose(stdin);
fclose(stdout);
return 0;
}
这里空空如也
有帮助,赞一个