1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 int main ()11 {12 int N;13 cin >> N;14 while(N--)15 {16 int n,m;17 cin >> n >> m;18 queue q;19 int List[11];20 memset(List,0,sizeof(List));21 while(n--)22 {23 int tmp;24 cin >> tmp;25 if(m == 0)26 {27 q.push(-tmp);28 m --;29 }30 else31 {32 q.push(tmp);33 m --;34 }35 List[tmp] ++;36 }37 38 int time = 0;39 while(!q.empty())40 {41 int i;42 for(i = abs(q.front())+1;i <= 9;i ++)43 {44 if(List[i])45 {46 int a = q.front();47 q.pop();48 q.push(a);49 break;50 }51 }52 if(i==10)53 {54 List[abs(q.front())] --;55 if(q.front()<0)56 {57 time ++;58 break;59 }60 q.pop();61 time ++;62 }63 // cout << q.front() << " ";64 }65 cout << time << endl;66 }67 return 0;68 }