Say No To Drugs Problem Code: NODRUGS
There are people participating in a race. The 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 , his speed is denoted by .
- The change in speed with one unit of the drug is units. Note that 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 .
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 , the number of test cases. Description of the test cases follows.
- First line of each test case will contain three space-separated integers, - the number of participants, - the change in speed with one unit of the drug, and - minimum units of the drug that can be detected in the drug test.
- Second line of each test case will contain space-separated integers , 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
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 , initial speeds are . You can inject unit of the drug into your friend's body, and increase his speed from to . is the fastest speed, thus you helped your friend win the race. Hence, the answer is "Yes".
- In test case , initial speeds are . You can inject unit of the drug into your friend's body, and increase his speed from to . But you can not inject any more units of the drug, and with speed your friend can only tie at rank and not Win. Hence, the answer is "No".
- In test case , initial speeds are . 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
Post a Comment