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 39 40 41 42 43
| #include <bits/stdc++.h> using namespace std;
bool Can(int now_priority,int *p){ for(int i=now_priority+1;i<=9;i++){ if(p[i]>=1)return 0; } return 1; }
void solve(){ int n,m,pri[105];cin>>n>>m; queue<pair<bool,int>> que; memset(pri,0,sizeof(pri)); for(int i=0;i<n;i++){ int p;cin>>p; if(i==m)que.push({1,p}); else que.push({0,p}); pri[p]++; } int ans = 0; while(!que.empty()){ auto cur = que.front(); que.pop(); if(Can(cur.second,pri)){ ans++; pri[cur.second]--; if(cur.first==1)break; } else que.push(cur); } cout<<ans<<endl; }
int main(){ int t;cin>>t; while(t--){ solve(); } }
|