Regarding Sums in a triaangle practice problem

This works fine on my machine but codechef shows a runtime error. Can anybody point out the problem?

``````#include<stdio.h>
#include<malloc.h>
#define MAX(a, b) (a > b) ? a : b;
char* tri = 0;
char rows;
int size[] = {1, 1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79, 92, 106, 121, 137, 154, 172, 191, 211, 232, 254, 277, 301, 326, 352, 379, 407, 436, 466, 497, 529, 562, 596, 631, 667, 704, 742, 781, 821, 862, 904, 947, 991, 1036, 1082, 1129, 1177, 1226, 1276,1327, 1379, 1432, 1486, 1541, 1597, 1654, 1712, 1771, 1831, 1892, 1954, 2017, 2081, 2146, 2212, 2279, 2347, 2416, 2486, 2557, 2629, 2702, 2776, 2851, 2927, 3004, 3082, 3161, 3241, 3322, 3404, 3487, 3571, 3656, 3742, 3829, 3917, 4006, 4096,4187, 4279, 4372, 4466, 4561, 4657, 4754, 4852, 4951, 5051, 5152};

void create(){

scanf("%d", &rows);
free(tri);
tri = malloc(size[rows+1]);

int i, j;
for(i=1; i< size[rows+1]; i++){
scanf("%d", tri+i);
}
}

void max(){
int i, j;

for(i=rows-1; i>=1; i--){
for(j = size[i]; j < size[i+1]; j++){
//printf("ppp%dppp\n", size[i] - size[i-1]+j);
tri[j] += MAX(tri[size[i] - size[i-1]+j+1], tri[size[i] - size[i-1]+j+2]);
}
//pr();printf("above printed by max");
}
}

void pr(){
int i, j;
//printf("\n--->\n");
for(i=1; i<=rows; i++){
for(j = size[i]; j < size[i+1]; j++){
printf("%d ", tri[j]);
}
printf("\n");
}
}

main(){
int n;
scanf("%d", &n);
for(;n>=1;n--){
create();
//pr();
max();
printf("%d\n", tri[1]);//pr();
}
return 0;
}``````

use this code to generate testing file and then run your code with that input:

``````#include <stdio.h>

#define T 99
#define VAL 99

int main() {
int v = 0;
printf("%d\n", T);
for ( int ii = 1; ii <= T; ++ii ) {
printf("%d\n", ii);
printf("%d\n", v++%100);
for ( int i = 2; i <= ii; ++i ) {
printf("%d", v++%100);
for ( int j = 1; j < i; ++j ) printf(" %d", v++%100 );
printf("\n");
}
}
return 0;
}``````

We are the Churches of The Detroit Metropolitan Association of The United Church of Christ. Our Association is 31 churches strong and growing! We are united in our faith and diverse in how we express that faith. We offer those in the community seeking new ways of Living a Spiritual Life in a world that often doesnâ€™t make sense, this website for sharing and caring. There are Best Church Websites.

//