Tuesday, March 19, 2019

LECANDY: Little Elephant and Candies

LECANDY: Little Elephant and Candies

Link for the Problem: LECANDY
This is the first problem of CCDSAP prepare.
Problem:
In the problem, you will be given the number of elephants and total no of candies in the zoo and an array of number where ith element denotes the number of candies by which ith elephant will be happy. You have to tell whether all the elephant can be happy or not.

Solution:
1. Take the summation of candies required by each elephant. Let it be S.
2. i) If it is less than or equal to total no of candies then print 'Yes'.
    ii) Else print 'No'.

Code:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,c;
        cin>>n>>c;
        int a[n],i,j,s=0;
        for(i=0;i<n;i++)
        {
            cin>>j;
            s+=j;
        }
        if(s>=c)
        printf("Yes\n");
        else
        printf("No\n");
    }
    return 0;
}

No comments:

Post a Comment

CHEFST: Chef and the stones

CHEFST: Chef and the stones Link for the problem:  CHEFST SOLUTION: For a given max possible no of stones that can be removed from ea...