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

×

Same Logic Written, but one is wrong answer

Hi All,

I am new to codechef, Yesterday I solved my first question in codechef. I have one doubt. Yesterday I solved Following Question (https://www.codechef.com/problems/LECANDY). There are two solutions which I tried, From my point of view both answer are correct, but in codechef first answer codechef is not accepting by giving me wrong_anser as output, but for second answer codechef accepted my answer, I need a reason why it is happening while both answers are correct.

*Note - I am using GOLANG as my Programming Language.

First Solution - Not Accepted BY CodeChef


package main

import ( "fmt" )

func main() { T := 0 fmt.Scan(&T) for i := 0; i < T; i++ { N, C := 0, 0 fmt.Scan(&N, &C) for j := 0; j < N; j++ { Temp := 0 fmt.Scan(&Temp) C -= Temp } if C < 0 { fmt.Println("No") } else { fmt.Println("Yes") } } }

Second Solution - Accepted By COdechef


package main

import ( "fmt" )

func main() { T := 0 SUM := 0 fmt.Scan(&T) for i := 0; i < T; i++ { N, C := 0, 0 fmt.Scan(&N, &C) for j := 0; j < N; j++ { Temp := 0 fmt.Scan(&Temp) SUM = SUM + Temp } if SUM > C { fmt.Println("No") } else { fmt.Println("Yes") } } }

asked 19 Aug, 14:26

nimishgupta95's gravatar image

0★nimishgupta95
11
accept rate: 0%

edited 19 Aug, 14:30

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:

×1,554
×825
×9

question asked: 19 Aug, 14:26

question was seen: 43 times

last updated: 19 Aug, 14:30