Source Code
#include <bits/stdc++.h>
using namespace std;

int main(){
	int tt;
	cin>>tt;
	while(tt--){
		int n,m;
		cin>>n>>m;
		int a[n];
		int b[m];
		int mx = 0, secondMx = 0;
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(a[i] >= a[mx]){
				secondMx = mx;
				mx = i;
			}	
			else if (a[i] > a[secondMx])
				secondMx = i;
		}
		int evens = 0, odds = 0;
		for(int i=0;i<m;i++){
			cin>>b[i];
			if(i % 2 == 0 && b[i] > a[secondMx])
				evens++;
			else if(i % 2 == 1 && b[i] > a[mx])
				odds++;
		}
		bool flagMx = (evens>odds) ? true : false;
		for(int i = 0 ; i<m ; i++){
			if(flagMx)
				cout<<mx+1<<' ';
			else 
				cout<<secondMx+1<<" ";
			flagMx = !flagMx;
		}
		cout<<endl;
	}
}
Copy
Ayoub vs Mahmoud hashemtb
GNU G++17
1 ms
184 KB
Wrong Answer