Given are the following values:
- N which are the number of days left for the exams.
- S which are the number of subjects to be prepared for the exam.
- C which are the number of chapters to be prepared for each subject.
- H which are the number of hours to prepare a chapter.
- L which are the number of days of desired vacation. During this vacation, study cannot be done.
- T which are the number of hours that one can study in a day.
The task is to find if the desired vacation can be taken or not. If it can be obtained, then print Yes, else print No.
Examples:
Input: N = 1, S = 2, C = 3, H = 4, L = 5, T = 6
Output: No
Required number of hours of study = S * C * H = 24 hours of study that can be done if the vacation is taken = (N – L) * T = -24 Since available time after vacation < total time required, Hence vacation cannot be taken.Input: N = 12, S = 5, C = 8, H = 3, L = 2, T = 20Â
Output: YesÂ
Required number of hours of study = S * C * H = 120 hours of study that can be done if the vacation is taken = (N – L) * T = 200 Since available time after vacation > total time required, Hence vacation can be taken.
Approach:
- Find the required number of hours of study by multiplying S, C and H.
required number of hours of study = S * C * H
- Now find the hours of study that can be done if the vacation is taken. These hours will be equivalent to the remaining days that we are left with multiplying by T hours(i.e., (N-L)*T).
hours of study that can be done if the vacation is taken = (N – L) * T
- Now check if the required hours are less than or equal to the hours of study that can be done if the vacation is taken. If true, then print Yes, else print No.
Below is the implementation of the above approach:
C++
// C++ program to find// if the Vacation can be taken or notÂ
#include <bits/stdc++.h>using namespace std;Â
// Function to find if the Vacation// is possible or notint isPossible(int N, int S, int C, int H,            int L, int T){Â
    // Find the required number of hours of study    int total_time_required = S * C * H;Â
    // find the hours of study that can be done    // if the vacation is taken    int available_time_after_vacation = (N - L) * T;Â
    // check if the required hours are less than    // or equal to the hours of study    // that can be done if the vacation is taken    if (available_time_after_vacation        >= total_time_required)        return 1;    return 0;}Â
// Driver Codeint main(){    int N = 12, S = 5, C = 8,        H = 3, L = 2, T = 20;Â
    if (isPossible(N, S, C, H, L, T))        cout << "Yes" << endl;    else        cout << "No" << endl;Â
    N = 1, S = 2, C = 3,    H = 4, L = 5, T = 6;Â
    if (isPossible(N, S, C, H, L, T))        cout << "Yes" << endl;    else        cout << "No" << endl;Â
    return 0;} |
Java
// Java program to find// if the Vacation can be taken or notclass GFG{Â
// Function to find if the Vacation// is possible or notstatic int isPossible(int N, int S, int C, int H,                    int L, int T){Â
    // Find the required number of hours of study    int total_time_required = S * C * H;Â
    // find the hours of study that can be done    // if the vacation is taken    int available_time_after_vacation = (N - L) * T;Â
    // check if the required hours are less than    // or equal to the hours of study    // that can be done if the vacation is taken    if (available_time_after_vacation        >= total_time_required)        return 1;    return 0;}Â
// Driver Codepublic static void main(String[] args){    int N = 12, S = 5, C = 8,        H = 3, L = 2, T = 20;Â
    if (isPossible(N, S, C, H, L, T) == 1)        System.out.print("Yes" + "\n");    else        System.out.print("No" + "\n");Â
    N = 1; S = 2; C = 3;    H = 4; L = 5; T = 6;Â
    if (isPossible(N, S, C, H, L, T)==1)        System.out.print("Yes" + "\n");    else        System.out.print("No" + "\n");}}Â
// This code is contributed by 29AjayKumar |
Python3
# Python3 program to find# if the Vacation can be taken or notÂ
# Function to find if the Vacation# is possible or notdef isPossible(N, S, C, H, L, T):         # Find the required number of hours of study    total_time_required = S * C * H         # find the hours of study that can be done    # if the vacation is taken    available_time_after_vacation = (N - L) * T         # check if the required hours are less than    # or equal to the hours of study    # that can be done if the vacation is taken    if (available_time_after_vacation >= total_time_required):        return 1    return 0Â
# Driver CodeN = 12S = 5C = 8H = 3L = 2T = 20Â
if (isPossible(N, S, C, H, L, T)):Â Â Â Â print("Yes")else:Â Â Â Â print("No")Â
N = 1S = 2C = 3H = 4L = 5T = 6Â
if (isPossible(N, S, C, H, L, T)):Â Â Â Â print("Yes")else:Â Â Â Â print("No")Â Â Â Â Â Â Â Â Â # This code is contributed by SHUBHAMSINGH10 |
C#
// C# program to find// if the Vacation can be taken or notusing System;Â
class GFG{Â
// Function to find if the Vacation// is possible or notstatic int isPossible(int N, int S, int C, int H,                    int L, int T){Â
    // Find the required number of hours of study    int total_time_required = S * C * H;Â
    // find the hours of study that can be done    // if the vacation is taken    int available_time_after_vacation = (N - L) * T;Â
    // check if the required hours are less than    // or equal to the hours of study    // that can be done if the vacation is taken    if (available_time_after_vacation        >= total_time_required)        return 1;    return 0;}Â
// Driver Codepublic static void Main(String[] args){    int N = 12, S = 5, C = 8,        H = 3, L = 2, T = 20;Â
    if (isPossible(N, S, C, H, L, T) == 1)        Console.Write("Yes" + "\n");    else        Console.Write("No" + "\n");Â
    N = 1; S = 2; C = 3;    H = 4; L = 5; T = 6;Â
    if (isPossible(N, S, C, H, L, T)==1)        Console.Write("Yes" + "\n");    else        Console.Write("No" + "\n");}}Â
// This code is contributed by 29AjayKumar |
Javascript
// JS program to find// if the Vacation can be taken or notÂ
// Function to find if the Vacation// is possible or notfunction isPossible(N, S, C, H, L, T){Â
    // Find the required number of hours of study    let total_time_required = S * C * H;Â
    // find the hours of study that can be done    // if the vacation is taken    let available_time_after_vacation = (N - L) * T;Â
    // check if the required hours are less than    // or equal to the hours of study    // that can be done if the vacation is taken    if (available_time_after_vacation        >= total_time_required)        return 1;    return 0;}Â
// Driver Codelet N = 12, S = 5, C = 8, H = 3, L = 2, T = 20;Â
if (isPossible(N, S, C, H, L, T))    console.log("Yes");else    console.log("No");Â
N = 1, S = 2, C = 3, H = 4, L = 5, T = 6;Â
if (isPossible(N, S, C, H, L, T))    console.log("Yes");else    console.log("No");     // This code is contributed by phasing17 |
Yes No
Time complexity: O(1) as constant operations are being performed
Auxiliary Space: O(1)
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

… [Trackback]
[…] There you will find 58937 more Info to that Topic: geeksforgeeks.org/find-if-the-vacation-can-be-taken-or-not/ […]
… [Trackback]
[…] Information to that Topic: geeksforgeeks.org/find-if-the-vacation-can-be-taken-or-not/ […]
… [Trackback]
[…] Read More on to that Topic: geeksforgeeks.org/find-if-the-vacation-can-be-taken-or-not/ […]