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

×

SUMTRIAN - Getting WA

I submitted this answer for the question SUMTRIAN. But I am getting WA. The test cases provided are working. I also tried some cases on my own. All seem to be giving the right answer. Can someone please point out the error? Thanks!

asked 25 Sep '13, 21:50

walterwhite's gravatar image

4★walterwhite
26258
accept rate: 0%

edited 25 Sep '13, 21:56


Your problem is on first line of function maxFromTop(). Because you have condition:

if(i>n)
    return 0;

If I understand your code properly, variable i indicates rows. But rows are numbered from 0 to n-1 inclusive, so they don't obtain row number n. So you should end, when i>=n.

if(i>=n)
    return 0;

Now the code should be correct.

link

answered 25 Sep '13, 23:07

michal27's gravatar image

5★michal27
1.1k21017
accept rate: 13%

Thanks a lot for sparing your time to find this silly error!!

(25 Sep '13, 23:13) walterwhite4★

you're welcome :)

(25 Sep '13, 23:31) michal275★

When I add first test case at the end it returns 5, 9, 8 instead of expected 5, 9, 5...

http://ideone.com/yQWiEq

link

answered 25 Sep '13, 22:54

betlista's gravatar image

3★betlista ♦♦
16.8k49115225
accept rate: 11%

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,480
×890
×270
×97
×47

question asked: 25 Sep '13, 21:50

question was seen: 1,696 times

last updated: 25 Sep '13, 23:31