No Time to Wait CodeChef Solution

Problem – No Time to Wait CodeChef Solution

Only x hours are left for the March Long Challenge and Chef is only left with the last problem unsolved. However, he is sure that he cannot solve the problem in the remaining time. From experience, he figures out that he needs exactly H hours to solve the problem.

Now Chef finally decides to use his special power which he has gained through years of intense yoga. He can travel back in time when he concentrates. Specifically, his power allows him to travel to N different time zones, which are T1​,T2​,…,TN​ hours respectively behind his current time.

Find out whether Chef can use one of the available time zones to solve the problem and submit it before the contest ends.

Input

  • The first line of the input contains three space-separated integers NH and x.
  • The second line contains N space-separated integers T1​,T2​,…,TN​.

Output

Print a single line containing the string "YES" if Chef can solve the problem on time or "NO" if he cannot.

You may print each character of each string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

Constraints

  • 1≤N≤100
  • 1≤x<H≤100
  • 1≤Ti​≤100 for each valid i

Subtasks

Subtask #1 (100 points): original constraints

Sample 1:

Input:
2 5 3
1 2
Output:
YES

Explanation:

Chef already has 3 hours left. He can go to the 2-nd time zone, which is 2 hours back in time. Then he has a total of 3+2=5 hours, which is sufficient to solve the problem.

Sample 2:

Input:
2 6 3
1 2
Output:
NO

Explanation:

If Chef goes to the 1-st time zone, he will have 3+1=4 hours, which is insufficient to solve the problem.

If he goes to the 2-nd time zone, he will have 3+2=5 hours, which is also insufficient to solve the problem.

Since none of the time travel options can be used to gain sufficient time to solve the problem, Chef is incapable of solving it.

No Time to Wait CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,h,x,a,flag;
	
	  cin>>n>>h>>x;
	  flag=0;
	  while(n--)
	  {
	    cin>>a;
	    if(a+x>=h)
	    {
	    flag=1;
	    break;
	    }
	  }
	  if(flag==1)
	  cout<<"YES"<<endl;
	  else if(flag==0)
	  cout<<"NO"<<endl;
	
	return 0;
}

No Time to Wait CodeChef Solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		int x= sc.nextInt();
		int h=sc.nextInt();
		int []a=new int[n];
		String ans="NO";
		for(int i=0;i<n;i++){
		    a[i]=sc.nextInt();
		    if((a[i]+h)>=x) ans="YES";
		}
		
		System.out.println(ans);
		
	}
}

No Time to Wait CodeChef Solution in Pyth 3

n,h,x=map(int,input().split())
t=list(map(int,input().split()))
for i in range(n):
    if t[i]+x>=h:
        print("YES")
        break
    i+=1
    if i==n:
        print("NO")
    
No Time to Wait CodeChef Solution Review:

In our experience, we suggest you solve this No Time to Wait CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the No Time to Wait CodeChef Solution

Find on CodeChef

Conclusion:

I hope this No Time to Wait CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *