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

×

SPOJ BYTESM2 : JAVA RUNTIME ERROR (NZEC)

I am using simple DP , cant find the reason for NZEC error.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class BYTESM2 {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws Exception {
        int t=Integer.parseInt(br.readLine());
        StringTokenizer inp;
        int maxSum=0,H,W;
        while(t-->0)
            {
                inp=new StringTokenizer(br.readLine());
                H=Integer.parseInt(inp.nextToken());
                W=Integer.parseInt(inp.nextToken());
                int arr[][]=new int[H+1][W+2];
                maxSum=0;
                for(int i=1;i<H+1;i++) {
                    inp=new StringTokenizer(br.readLine());
                    for(int j=1;j<W+1;j++) {
                         arr[i][j]=Integer.parseInt(inp.nextToken())+Math.max(arr[i-1][j-1], Math.max(arr[i-1][j], arr[i-1][j+1]));
                         if(i==H && arr[i][j]>maxSum)maxSum=arr[i][j];
                    }
                }
                pw.println(maxSum);
            }
        pw.close();
    }
}

asked 31 Aug '14, 13:04

adarshhsingh's gravatar image

2★adarshhsingh
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:

×2,086
×1,280
×1,115
×419
×18

question asked: 31 Aug '14, 13:04

question was seen: 2,370 times

last updated: 31 Aug '14, 13:04