Say No To Drugs Problem Code: NODRUGS

 



Say No To Drugs Problem Code: NODRUGS

There are N people participating in a race. The Nth participant is your friend, so you want him to win. You are not a man of ethics, so you decided to inject some units of a Performance Enhancement Drug (don't ask where that came from) in your friend's body.

  • From the charts, you came to know the speed of every player. Formally, for a player i, his speed is denoted by Si.
  • The change in speed with one unit of the drug is K units. Note that K can be negative, which means the drug has more side effects than benefits.
  • Of course, there will be a drug test before the race, so your friend will be caught if the number of units of the drug in his blood is greater than or equal to L.

You need to determine whether you can help your friend to win the race (with or without drugs), without getting caught.

Note: A player wins the race if he has the maximum speed among all the participants. If there are more than one people with a maximal speed, they tie at first place, and no one wins!

Input Format

  • First line will contain a single integer T, the number of test cases. Description of the test cases follows.
  • First line of each test case will contain three space-separated integers, N - the number of participants, K - the change in speed with one unit of the drug, and L - minimum units of the drug that can be detected in the drug test.
  • Second line of each test case will contain N space-separated integers Si, the speeds of the participants.

Output Format

For each test case print "Yes" if you can help your friend to win the race, otherwise "No" in a single line.

Constraints

  • 1T200
  • 1N,L1000
  • 1000K1000
  • 1Si1000

Sample Input 1 

3
4 2 2
2 1 3 2
4 2 2
2 1 4 2
3 -10 100
12 11 9

Sample Output 1 

Yes
No
No

Explanation

  • In test case 1, initial speeds are {2,1,3,2}. You can inject 1 unit of the drug into your friend's body, and increase his speed from 2 to 44 is the fastest speed, thus you helped your friend win the race. Hence, the answer is "Yes".
  • In test case 2, initial speeds are {2,1,4,2}. You can inject 1 unit of the drug into your friend's body, and increase his speed from 2 to 4. But you can not inject any more units of the drug, and with speed 4 your friend can only tie at rank 1 and not Win. Hence, the answer is "No".
  • In test case 3, initial speeds are {12,11,9}. Note that the impact of the drug in this case is negative, which means that the speed will only decrease if you inject it. So, there is no way you can help your friend to win. Hence, the answer is "No".















































































SOLUTION IN C++



#include <iostream>

#include<bits/stdc++.h>

#define ll long long int

using namespace std;


void sol(){

    ll n,k,l;

    cin>>n>>k>>l;

    vector<ll>v(n);

    for(ll i=0;i<n;i++){

        cin>>v[i];

    }

    if(k>0){

        ll take=max((ll)0,(ll)l-1);

        v[n-1]+=(ll)take*k;

    }

    else

    {

        

    }

    int ma=-1e9;

    int cnt=0;

    for(ll i=0;i<n;i++){

        if(ma<v[i]){

            ma=v[i];

            cnt=1;

        }

        else if(ma==v[i]){

            cnt++;

        }

    }

    if(v[n-1]==ma && cnt==1){

        cout<<"Yes";

    }

    else{

        cout<<"No";

    }

    cout<<"\n";

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int t;

    cin>>t;

    while(t--){

        sol();

    }

}

Comments

Popular posts from this blog

Bhutan : The Happiest Place On Earth.

Airline Restrictions Solution September Challenge 2021 (Rated for Div 3)

Minimize Digit Sum Solution | Codechef September long challenge 2021

The Old Saint And Three Questions Problem Code: THREEQ

THE TOP 10 YOUTUBERS IN 2020

10 things you need to know about SpaceX

Maximise the Subsequence Sum Problem Code: SIGNFLIP Codechef Solution

THE TOP 10 PAID BLOGGERS IN 2020

2-D Point Meeting Solution | Codechef September long challenge 2021

Why the SpaceX Falcon Heavy Rocket Is Such a Big Deal for Elon Musk