I submitted the first problem yesterday and got WA. I got demotivated and left because the first problem was the easiest. Today, I came back online and saw (with some pleasant surprise and happiness) that it did get accepted ! Can someone explain what happened ?
What is wrong with my solution? I have tested all possible test cases.This is my submission for LOSTMAX from LTIME50. Further clarifications on where I went wrong is appreciated. Thank You.
@sprea27
If c[0]=c.size()-1 and it is the greatest element then your code give that as output which is wrong.
Input
3 1 2 1
your code output:3
correct output: 2
So put c=0 or any negative number and run loop from 0.You will get AC.
Second TC has array numbers >9, i.e. 2 digit numbers. If you are taking entire line as input (as string), then make sure you are correctly assigning values to array. I.e. storing 19 in array instead of 1 and 9 in 2 adjacent indices.
Maybe languages like python can help a Lot in these cases.
We can take input without reading the number of inputs in single line in python
while input().split() and using map().
Makes code really simple.
Clean Code https://www.codechef.com/viewsolution/24351745
I think there’s no need of getline()
beginners can do it easily with the clean logic below
use only array to read integers
read space using getchar() alternatively
then sort the array
l is the desired value
can see my sol here easy solution here no knowledge of strings required