×

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".

19.0k348495533
accept rate: 37%

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 <iostream>

using namespace std;

int main() { int T; cin >> T; for (int t = 0; t < T; ++t) { int N, C; cin >> N >> C; for (int i = 0; i < N; ++i) { int Ai; cin >> Ai; C -= Ai; } cout << (C < 0 ? "No" : "Yes") << endl; } return 0; }

1
accept rate: 0%

# 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; }

0★dipjul
1
accept rate: 0%

 0 int main() { int t=0; cin >> t; while(t--){ unsigned int n=0,c=0,i,a[102], total=0; cin >> n >>c; for(i=0;i>a[i]; total=total+a[i]; } if(total<=c) cout<<"Yes\n"; else cout<<"No\n"; } return 0; } answered 14 Dec '17, 18:38 1 accept rate: 0%

# include <stdio.h>

int main(){ int arr[3] = {1,2,3 } ; //elephants

int candies[3] = {2,2,1 } ; //candies

int i ;

int x; x = &arr[i]; int y; y = &candies[i];

for(i=0; i<=2; i++ ) { if (candies[ i ] >= arr[ i ]) { printf("yes "); } else printf("no ");

} }

/ i guess my approach is correct. how can i improve my code? :( /

0★pari97
32
accept rate: 0%

# include<stdio.h>

int main() {

int i,T,ii;
scanf("%d",&T);
for(i=0;i<T;i++)        //for test cases
{   int C,N;
scanf("%d %d",&N,&C);
int E[N];
for(ii=0;ii<N;ii++)            //assigning candies to elephants
{

scanf("%d",&E[ii]);
if(C>=ii)               //for assign only grater or equal index number candy to elephant
{
C=C-E[ii];
}
else {
C=-1;
}

}
if(C >=0)
printf("Yes");
else
printf("No");
}
return 0;


}

1
accept rate: 0%

 0 I'm getting NZEC and unable to understand why? Please help import java.io.IOException; import java.util.Scanner; public class Main{ public static void main(String args[]){ lecandy(); } public static void lecandy(){ //Scanner in = new Scanner(System.in); try{ java.io.BufferedReader r = new java.io.BufferedReader(new java.io.InputStreamReader (System.in)); int t = Integer.parseInt(r.readLine()); while(t>0){ int N = Integer.parseInt(r.readLine()); int C = Integer.parseInt(r.readLine()); // int Ak[] = new int[N]; int sum = 0; for(int i=0;i
 0 int sumOfCandies = 0; for(int i=0;i= sumOfCandies){ System.out.println("Yes"); } else{ System.out.println("No"); } answered 22 Jan, 11:58 1 accept rate: 0%
 0 This is for giving inputs in single line in python N, C = map(float, input().split())  This is for giving inputs in a single line for list A = [] A = map(float,input().split(' '))  link This answer is marked "community wiki". answered 28 Jan, 11:32 2★kd90 1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

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:

×14,482
×1,434
×760
×18
×7

question asked: 11 Jun '12, 22:15

question was seen: 8,738 times

last updated: 09 Jul, 15:54