As a I have posted the possible solution to a CodeForce Problem which was causing Time Limit Exceed error posted enter link description here, some solutions came. Nevertheless I worked out with another solution..
#include <stdio.h>
#include <string.h>
int greatestX = 0, greatestY = 0;
int counter = 0;
void prune_boxes(int boxes[][greatestY], int x, int y){
printf("boxes[2][0] = %d\n", boxes[2][0]);
if (y < 0)
return;
else{
//printf("x = %d y = %d\n", x, y);
if (boxes[x][y] == 0){
printf("x = %d y = %d\n", x, y);
counter++;
boxes[x][y] = 1;
}
prune_boxes(boxes, x, y - 1);
prune_boxes(boxes, x + 1, y - 1);
}
}
int main() {
int wetBoxes, i, j;
scanf("%d", &wetBoxes);
int coordinates[wetBoxes][2];
for(i = 0; i < wetBoxes; i++){
scanf("%d%d", &coordinates[i][0], &coordinates[i][1]);
if (coordinates[i][0] > greatestX)
greatestX = coordinates[i][0];
if (coordinates[i][1] > greatestY)
greatestY = coordinates[i][1];
}
int boxes[greatestY + 1][greatestY + greatestX + 1];
memset(boxes, 0, sizeof(boxes));
/*
for(i = 0; i < greatestY + 1; i++){
for (j = 0; j < greatestY + greatestX + 1; j++){
printf("%d ", boxes[i][j]);
}
printf("\n");
}
*/
for(i = 0; i < wetBoxes; i++){
//printf("value = %d\n", boxes[coordinates[i][0]][coordinates[i][1]]);
prune_boxes(boxes, coordinates[i][0], coordinates[i][1]);
}
printf("counter = %d\n", counter);
return 0;
}
Is not causing the the Time Limit Exceed now but it is giving me one less count of any particular value.
Debugging it further I found that for the input of (1, 3) the code is not counting the coordinate (2, 0).
Even with further debugging I found that boxes[2][0] is becoming 1 before I would actually make that coordinate 1 manually.
The sample output looks like this
1
1 3
boxes[2][0] = 0
x = 1 y = 3
boxes[2][0] = 1
x = 1 y = 2
boxes[2][0] = 1
x = 1 y = 1
boxes[2][0] = 1
x = 1 y = 0
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
x = 2 y = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
x = 3 y = 0
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
x = 2 y = 2
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
x = 3 y = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
boxes[2][0] = 1
x = 4 y = 0
boxes[2][0] = 1
boxes[2][0] = 1
counter = 9
As you can see that the boxes[2][0] from the second recursion level is becoming 1 but why ?
Edit

void foo(size_t x, size_t y, int p[x][y]);. Order matters.j...Moreover how passingx,ybeforepwould make any difference ??