Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

LECANDY - Editorial

$
0
0

PROBLEM LINKS:

Practice
Contest

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Basic knowledge of arrays and loops.

PROBLEM:

The program asks you to calculate if all the elephants would get the number of candies that they want.

EXPLANATION:

If there are C candies in all, and elephant i needs A[i] candies, then it is possible to serve all the elephants only if there are enough candies available, i.e. the following condition must be satisfied:

C >= A[0] + A[1] + ... + A[N-1]

This means you can have a simple loop over the array A to count the sum of the required number of candies by the elephants and then finally comparing it with C to determine the answer. If the above condition is satisfied, answer will be Yes, else the answer will be No (they have to be case-sensitive to avoid WA).

SETTER'S SOLUTION:

Can be found here.

APPROACH:

The problem setter used the above solution to solve the problem.

TESTER'S SOLUTION:

Can be found here.

APPROACH:

The problem tester used the above solution to solve the problem.


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>