You are not logged in. Please login at www.codechef.com to post your questions!

×

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.

This question is marked "community wiki".

asked 11 Jun '12, 22:15

15.9k347484508
accept rate: 35%

really nice, waiting for the next editorials ;-)

(11 Jun '12, 23:31)
1

This can't be better!! :D

(12 Jun '12, 00:25)

# include <stdio.h>

int main(){

int t,n,i,j; int A[1000]; long long int c; scanf("%d",&t); for(i=0;i<t;i++){ scanf("%d",&n); scanf("%lli",&c); for(j=0;j<n;j++){ scanf("%d",&A[j]); c=c-A[j]; } if(c<0){ printf("No\n"); } else{ printf("Yes\n"); }

} return 0; }

answered 14 Oct, 21:19

0★dipjul
1
accept rate: 0%

 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×11,590
×1,049
×528
×15
×7

question asked: 11 Jun '12, 22:15

question was seen: 4,406 times

last updated: 14 Oct, 21:19