CHEFBM - Editorial

I really hate to do this,but i can’t figure out the error in this:
http://www.codechef.com/viewsolution/3902790
if anyone can provide any corner test cases.Thanks.

http://www.codechef.com/viewsolution/3903340
my code is working fine on my computer.but here i am getting wrong answer

remove

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

at least

1 Like

http://www.codechef.com/viewsolution/3904846 is my solution to the problem, I have tried all the test cases provided in the above answers and also the sample test case and it is working fine, I’m not able to figure out why my code is getting a WA.

Please help me to figure it out.

Can someone please provide a test case for which my answer gives WA?
Here’s my solution. :http://www.codechef.com/viewsolution/3894003

Can anybody spot where am i going wrong?

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

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

hey its working for test cases on my pc why it is showing Runtime error on here please Help!!
www.codechef.com/viewsolution/3932903

For such a query we also store (j-1,0) and (j+1,0), because these two indexes are also effected."

Can anyone expand on this line? Where do we store that?

@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.

i ma getting compilation error due to array size is too large …
#include <bits/stdc++.h>
using namespace std;
int max(int a,int b)
{
return ((a)>(b)?(a):(b));
}
int a[100000][100000];
int main() {
// your code goes here
int n,m,p,i,j,ans,x,y,flag=0;
cin>>n>>m>>p;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
a[i][j]=j;
}
}
while(p–)
{
cin>>x>>y;
a[x][y]=a[x][y]+1;
}
for(i=1;i<=n;i++)
{
ans=0,flag=1;
for(j=m;j>1;j–)
{
if(a[i][j]>=a[i][j-1])
{
ans=ans+(a[i][j]-a[i][j-1]);
}
else
{
flag=0;
break;
}
}
if(flag==0)
cout<<"-1"<<endl;
else
cout<<ans<<endl;
}
return 0;
}