[SOLUTION] To Do List solution codechef 2021 – Code Cracker codechef

To Do List solution codechef 2021

To Do List solution codechef 2021

It’s 10:30 pm and Khushi is trying to make a to-do list for the next day. There are NN tasks where each task requires HH hours to complete. Considering she takes XX hours in completing her mundane tasks, determines whether she will be able to finish all the tasks the other day.

Input: To Do List solution codechef 2021

  • The first line of input contains two integers N,XN,X
  • The second line of input contains NN integers hh11hh22hh33hh44,…., hhnn.

Output: To Do List solution codechef 2021

  • Print a single line containing the string “YES” if it is possible for her to successfully complete all the tasks or “NO” if it is impossible (without quotes).

Constraints To Do List solution codechef 2021

  • 0<N<250<N<25
  • 0X<250≤X<25
  • 0<0< hii <104<104

Sample Input: To Do List solution codechef 2021

5 8
3 2 3 3 1

Sample Output: To Do List solution codechef 2021

YES

To Do List solution codechef 2021

Problem Code :

C++

#include <bits/stdc++.h>
using namespace std;

int main() {
int n,x,sm=0;
cin>>n>>x;
int ar[n];
for(int i=0;i<n;i++)
{
cin>>ar[i];
sm+=ar[i];
}
if((24-x)>=sm)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}

return 0;
}
Python 

n, k = map(int, input().split())
a = list(map(int, input().split()))
if sum(a)+k <= 25:
print('YES')
else:
print('NO')
JAVA


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


class code
{
static class RealScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");

String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}

int nextInt() {
return Integer.parseInt(next());
}

int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}

long nextLong() {
return Long.parseLong(next());
}
}

public static void main(String[] args) {
RealScanner sc=new RealScanner();
int n,k;
n=sc.nextInt();
k=sc.nextInt();
//int[] arr=new int[n];
int sum=0;
int count=0;
for (int i=0;i<n;i++){
int a=sc.nextInt();
sum+=a;
}
//System.out.println(sum);
if (sum+k<=24){
System.out.println("YES");
}else {
System.out.println("NO");
}

}
}

C

#include <stdio.h>

int main(void) 
{
int n,x;
scanf("%d",&n);
scanf("%d",&x);
int arr[n],sum=0;
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
sum+=arr[i];
}
if((sum+x)>24)
printf("NO");
else
printf("YES");
return 0;
}

Also read : Flower Sequence solution codechef 2021

To Do List solution codechef 2021

 

Leave a Comment