# PROBLEM LINK:

Practice

Author: Divyam Arora
Tester: Jaymeet Mehta Raksha Jain Smit Mandavia Taranpreet Singh
Editorialist: Divyam Arora

CAKEWALK

Implementation

# PROBLEM:

Given a circular path with two starting points of race A and B strictly opposite to each other and N checkpoints( 1 unit difference between every adjacent checkpoint). One team starts from A and other from B. Speed of every team member of both team is defined as the number of checkpoints covered in 1 second.
You need to find out if race will end or not.

# QUICK EXPLANATION:

If the maximum speed of A is not equal to maximum speed of B then only the race will end.

# EXPLANATION:

The problem statement clearly states that both the points A and B are opposite to each other. The speed depicts the number of checkpoints covered in a second by every player.
So initially every player of one team is standing opposite to all players of opponent team and when the race starts the player(s) with same speed as of the opponent team player will always run opposite to each other as the checkpoints covered every second are equal. But if a player X has speed greater than the speed of any opponent player Y then X will surely overtake Y because the distance/checkpoints covered every second by X is greater than the distance/checkpoints covered every second by Y. So at a certain point of time in future X will overtake all the opponents with speed lesser than it. But this doesnâ€™t mean that the race will end here, it ends only when X is the player with the maximum speed which is greater than maximum speed of opponent team player. Note X can be the player of team A or team B.
In short if maxSpeed(A) < maxSpeed(B) OR maxSpeed(A) > maxSpeed(B) then the race will end.

# SOLUTIONS:

Setter's Solution
``````#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n],b[n],maxA=0,maxB=0;
for(int i=0;i<n;i++){
cin>>a[i];
maxA=max(maxA,a[i]);
}
for(int i=0;i<n;i++){
cin>>b[i];
maxB=max(maxB,b[i]);
}
if(maxA!=maxB)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
``````