Quote:
Can someone please tell me why is this code not being accepted? Note:I am not asking for a solution, just tell me where this code fails
Your problem is that your code is the correct answer to another question.
you compute the maximum of each lines and then add the maximums while checking they respect the secondary constraint.
You have a goal:
Compute the maximum possible value of E1 + E2 + ... + EN. If it's impossible to pick the elements E1, E2, ..., EN, print -1 instead.
and a constraint:
You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1.
You have never been told to use the maximum of each line.
You have to use the maximum value that respect the constraint.
Input:
1
3
6 2 3
11 5 6
7 8 9
Output:
3 + 6 + 9 = 18
[Update]
You must understand that a full explanation means that you failed the contest.
You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1.
The constraint is constructed in such a way that it imply to compute the maximum allowed of each line in reverse order.
For practical considerations, you must reverse the constrain to:
For each i (1 ≤ i ≤ N-1), Ei should be strictly lower than Ei+1.
And last line have no constraint.
Input:
1
3
6 2 3
11 5 6
7 8 9
Solving:
7 8 9: no constraint, 7 8 9 qualified, maximum is 9.
11 5 6: constraint is < 9, 5 6 qualified, maximum is 6.
6 2 3: constraint is < 6, 2 3 qualified, maximum is 3.
output is: 9+6+3=18
1
3
6 10 12
8 15 7
8 19 10
Solving:
8 19 10: no constraint, 8 19 10 qualified, maximum is 19.
8 15 7: constraint is < 19, 8 15 7 qualified, maximum is 15.
6 10 12: constraint is < 15, 6 10 12 qualified, maximum is 12.
output is: 19+15+12=46