Is codechef a fucking retard?
Or am I?
I have this problem to solve: https://www.codechef.com/problems/SUMTRIAN
And this was my proposed solution: http://pastebin.com/TuXJ0FUw
It follows the logic of pic related.
Works fine with the test values and some of my own.
Codechef says the answer is wrong.
Is it right or not?!
Have a more readable version of the code.
>>58493702
>this feminine code
>>58493702
From what I can tell your code look ahead at all, for example
Given1
1 2
1 2 3
1 5 2 1
your code will sum 1, 2, 3, 2 and give the total 8.
However if it summed 1, 2, 2, 5 it would give the total 10.
Because it cannot step left once it picks the 3 it is stuffed.
Also, fix your indents and use braces all the time, sloppy shit makes the code less obvious (look at line 17 for example)
>>58495157
whats wrong with 17? looks good to me.
>>58493702
>everything in main()
>>58495182
Line 17 is not part of the for loop above it, because without braces only the following line is looped, yet it is indented the same as line 16 which is in the for loop.
Of course, it logically shouldn't be in the loop anyway or else the loop would loop infinitely, but that isn't the point.
uhhh is codechef another spoj reskin?
This is my solution to the problem.
I haven't tested it much but it seems to work.
http://pastebin.com/5KsjfweP
>>58495157
You can test my code at: https://www.codechef.com/ide just copying and pasting the pastebin and inserting the input you suggested. It outputs 10 as it should.
You didn't seem to understand my code, it tests every possibility.
>>58495241
Come one man, it's a short code.
Okay I fixed the indentations.
The pastebin link remains the same.
Have the updated pic.
No one proved my code wrong yet.
Can it be that codechef just fucked up with the test cases and their supposedly correct outputs?
>>58493702
>scanf
>>58499271
cin from C++ consumes way too many resources figuring out the data type to make for a neat and clean solution.
There was another possible path and I didn't consider it.
Thanks everyone for your help.