You are not logged in. Please login at www.codechef.com to post your questions!

×

sumtrian : lot of test cases tried but still wa

# 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);

    }
}

asked 05 Jun '14, 17:48

sidak's gravatar image

4★sidak
11
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×3,705
×1,901
×1,056
×53

question asked: 05 Jun '14, 17:48

question was seen: 712 times

last updated: 05 Jun '14, 17:48