CHEFBM - Editorial

at least you are getting RE for

 100000 100000 1
 1 1

Iā€™m getting compilation error on IdeOne - xhCPmz - Online C# Compiler & Debugging Tool - Ideone.com

Try

100000 100000 1
1 1

on your computerā€¦

but on VS2010 it is working fine. also on codechef, WA is coming, Not the compilation error

authorā€™s sol is not accessible??

according to me ā€œThe value only changes if the 1st nd lst values are changedā€ā€¦is that right??

Will this work for this test caseā€¦?

100000 100000 100000

1 1

1 2

1 3

.

.

.

1 100000

Its easy using map etc without sort. @miiitd7042075 My sort logic is like taking one count array[m] where the array index will be the coloumn value, iā€™ll increment each time as per the input.
i.e if in input (taking m=4) for row 2, colomn 3(incremented twice) and 4 incrmented once i.e. array for row 2 will be 0201 (array is 1 indexed). Add the index values to it i.e. array is now 1435(doing this way 0+1, 2+2, 3+0, 4+1). This array finaly should be in sorted order for ans to be m-1 else ans=-1.

remove

printf("input:");
printf("output:");

at least

1 Like

Limits for M are not clear, should not it be M>=2 instead of M>=1, How could M == 1?

Why canā€™t we just store j and j+1 on query (i,j), because j-1 is already in order? I am storing in sorted map to check if j < j+1

Can somebody please tell me what is wrong with this approach

http://www.codechef.com/viewsolution/3915841

@darkshadows (or anyone else) sir, please elaborate how when a[i][j] is incremented j-1th index is also affected. I feel that the difference a[i][j]-a[i][j-1] may change, but the overall sum doesnā€™t change and it would be a[i][m]-a[i][0]. Also jth element is always greater than j-1th element for that particular increment. Hence the only index that is affected should be j+1.

found that j-1th element is not affected. Reason is clearly mentioned in the code. AC code can be viewed here.

@imdeepakg: it is sufficient to check j and j+1 on query (i,j). Here is my well commented accepted code link. As far as your approach is concerned I am not good in JAVA and not able to understand the code. Hope that my code may help you debug your code.

@birazdeli: check this well commented code. Hope this helps. Also, it is sufficient to check j+1 element. j-1 element is not required when j element is modified.