Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

sumtrian : lot of test cases tried but still wa

$
0
0
# include <iostream>
# include <stdio.h>
# include <math.h>
# include <list>
# include <algorithm>
using namespace std;
int arr[100][100], val_arr[100][100]={0};
int value (int x,int y){
    if((!arr[x-1][y])&&(!arr[x-1][y-1])){
        return arr[x][y];
    }
    else if ((!arr[x-1][y])){
        return (arr[x][y]+val_arr[x-1][y-1]);
    }
    else if ((!arr[x-1][y-1])){
        return (arr[x][y]+val_arr[x-1][y]);
    }
    else{
        return ( val_arr[x-1][y-1]>=val_arr[x-1][y]? (arr[x][y]+val_arr[x-1][y-1]):(arr[x][y]+val_arr[x-1][y]) );
    }
}
int main(){

    int t;
    scanf("%d",&t);
    for(int i=0; i<t; i++){
        int n;
        scanf("%d",&n);
        for(int j=0; j<n; j++){
            for(int k=0; k<=j; k++){
                scanf("%d",&arr[j][k]);
                val_arr[j][k]=value(j,k);
            }
        }
        int ans=-1;  
        for(int j=0; j<n; j++){
            if(val_arr[n-1][j]>ans){
                ans=val_arr[n-1][j];
            }
        }
        printf("%d\n", ans);

    }
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles