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

×

LECANDY - Editorial

15
1

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.

This question is marked "community wiki".

asked 11 Jun '12, 22:15

admin's gravatar image

0★admin ♦♦
19.0k348495533
accept rate: 37%

edited 25 Dec '12, 15:04

really nice, waiting for the next editorials ;-)

(11 Jun '12, 23:31) betlista ♦♦3★
1

This can't be better!! :D

(12 Jun '12, 00:25) javadecoder4★

12next »

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

link

answered 02 Oct '17, 19:26

chandrika1295's gravatar image

2★chandrika1295
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; }

link

answered 14 Oct '17, 21:19

dipjul's gravatar image

0★dipjul
1
accept rate: 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<n;i++){ cin="">>a[i]; total=total+a[i]; } if(total<=c) cout<<"Yes\n"; else cout<<"No\n"; } return 0; }

link

answered 14 Dec '17, 18:38

kk_the_coder's gravatar image

1★kk_the_coder
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? :( /

link

answered 19 Dec '17, 00:41

pari97's gravatar image

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;

}

link

answered 24 Dec '17, 22:00

dvarc33343's gravatar image

0★dvarc33343
1
accept rate: 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<N;i++){
//              Ak[i] = in.nextInt();
                sum+=Integer.parseInt(r.readLine());
            }
            if(sum<=C){
                System.out.println("Yes");
            }else{
                System.out.println( "No");
            }
            t--;
        }
        r.close();
        }catch(IOException e){
            e.printStackTrace();
        }


    //  in.close();
    }
}
link

answered 09 Jan, 09:07

sank20's gravatar image

2★sank20
1
accept rate: 0%

Answer is hidden as author is suspended. Click here to view.

answered 10 Jan, 12:36

jeojohn's gravatar image

0★jeojohn
(suspended)
accept rate: 0%

Answer is hidden as author is suspended. Click here to view.

answered 10 Jan, 14:20

treatment's gravatar image

0★treatment
(suspended)
accept rate: 0%

int sumOfCandies = 0; for(int i=0;i<a.leght;i++){ sumofcandies="A[i]" +="" sumofcandies;="" }="" if(c="">= sumOfCandies){ System.out.println("Yes"); } else{ System.out.println("No"); }

link

answered 22 Jan, 11:58

az1az09_3143's gravatar image

0★az1az09_3143
1
accept rate: 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

kd90's gravatar image

2★kd90
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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