kings-race-8

Shizuka, the daughter of Code King, is the most beautiful girl of Candyland. Every other Prince wants to marry her.The Code King invites all the other Prince in the town for a RACE and the winner of the race gets a chance to marry her.

Obviously , the RACE will be full of hurdles. Given the number of Princes N, each with ID (0 to N-1) and their maximum jumping strengths (A[i] : i = 0,1,...,N-1) and the
number of hurdles K, each with its height ( D[i] : i = 0,1,...K-1) in the RACE, find the winner !!

The Prince who crosses maximum number of levels wins the RACE. In case of ties, the Prince with minimum ID wins the RACE.

for further clarification refer the testcases.

INPUT:
First line of input contains a single integer t denoting the number of test cases .
first line of each test case contains two space separated integers N and K denoting the total number of Princes and the number of hurdles.

The second line of each test case contains N space separated integers A[0],A[1],...,A[N-1] denoting princes jumping strength.

The third line of the each test case contains K space separated integers D[0],D[1],..,D[K-1] denoting height of hurdle i.

OUTPUT:
output a single integer denoting the ID of the winning prince.

CONSTRAINTS:
1 ≤ t ≤ 50
1 ≤ N ≤ 10^6
1 ≤ K ≤ 10^6
0 ≤ A[i] ≤ 10^9
0 ≤ D[i] ≤ 10^9

SAMPLE INPUT
2
5 5
10 20 30 40 50
7 7 7 7 7
7 5 
1 2 3 4 5 6 7
2 1 5 1 8

SAMPLE OUTPUT
0
4

Explanation

In the 1st test case all the princes can finish the race therefore the answer is 0 (MINIMUM ID)
In the 2nd test case princes with ID 4,5,6 cannot jump over the last hurdle i.e(hurdle 5) therefore the answer is 4(MINIMAL ID)

Source: hackerearth | Difficulty: EASY
Tags: Sorting


Solutions:
tc = int(input())
for t in range(tc):
	n, k = [int(c) for c in input().rstrip().split(" ")]
	n_arr = [int(c) for c in input().rstrip().split(" ")]
	k_arr = [int(c) for c in input().rstrip().split(" ")]
	n_max = max(n_arr)
	k_max = max(k_arr)
	if k_max>n_max:
		for k_val in k_arr:
			if k_val>n_max:
				k_max=k_val
				break;
		k_arr = k_arr[:k_arr.index(k_max)]
		if len(k_arr)==0:
			k_max = 0
		else:    
			k_max = max(k_arr)
	i=0
	while n_arr[i]<k_max:
		i+=1
	print(i)
	
		


cases=int(input())
flag=False;
flag2=False;





for i in range(cases):
	t=input().split()
	princes_cnt=int(t[0])
	hurdles_cnt=int(t[1])
	t=input().split()
	strengths=[int(x) for x in t]
	t=input().split()
	heights=[int(x) for x in t]
	h=0
	p=0

	
	for j in range(princes_cnt):
		
		strength=strengths[j]
	
		for k in range(h,hurdles_cnt):
			if(strength<heights[k]):
				break;
		if(k>h):
			h=k
			p=j
			
			
			
			
			
		
	print(p)