Hello the code i have submitted is correct,but i dont know why i got WA judgement
===================================================================================
package dsproject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
-
To change this license header, choose License Headers in Project Properties.
-
To change this template file, choose Tools | Templates
-
and open the template in the editor.
/
/* -
@author samuel
*/
public class Main {public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
int n = 0, preCnt = 0, postCnt = 0, preD = 0, left_Index = 0, right_Index = 0;
long result = 0, aux = 0;
char ls[] = null;
String vl[] = null;
for (int i = 0; i < t; i++) {
n = Integer.parseInt(br.readLine());
ls = br.readLine().toCharArray();
vl = br.readLine().split(" ");if (n == 1) { System.out.println(0); continue; } result = 0; preCnt = 0; postCnt = 0; preD = 0; left_Index = 0; right_Index = 0; if (ls[0] == '0') { for (int j = 1; j < n; j++) { if (ls[j] == '1') { preCnt = Integer.parseInt(vl[j]) - Integer.parseInt(vl[0]); left_Index = j; for (int k = j + 1; k < n; k++) { if (ls[k] == '0') { left_Index = k - 1; break; } } break; } } } if (ls[0] == '1') { for (int j = 1; j < n; j++) { if (ls[j] == '0') { left_Index = j - 1; break; } } } if (ls[n - 1] == '1') { right_Index = n - 1; for (int j = n - 2; j >= 0; j--) { if (ls[j] == '0') { right_Index = j + 1; break; } } } if (ls[n - 1] == '0') { right_Index = n - 1; for (int j = n - 2; j >= 0; j--) { if (ls[j] == '1') { postCnt = Integer.parseInt(vl[n - 1]) - Integer.parseInt(vl[j]); right_Index = j; for (int k = j - 1; k >= 0; k--) { if (ls[k] == '0') { right_Index = k + 1; break; } } break; } } } result = preCnt + postCnt; int maxD = 0; if (right_Index != left_Index) { maxD = -1; for (int j = left_Index; j < right_Index; j++) { if (ls[j + 1] != '1') {//if it is 0 preD = Integer.parseInt(vl[j + 1]) - Integer.parseInt(vl[j]); if (maxD <= preD) { maxD = preD; } } else {//if it is 1 preD = Integer.parseInt(vl[j + 1]) - Integer.parseInt(vl[j]); if (maxD <= preD) { maxD = preD; } aux = Integer.parseInt(vl[j + 1]) - Integer.parseInt(vl[left_Index]); aux = aux - maxD; result += aux; maxD = -1; int k = j+2; for (; k <= right_Index; k++) { if (ls[k] != '0') { left_Index = k - 1; j = left_Index; j--; break; } } } } } System.out.println(result); } } catch (IOException ex) { }
}
}
====================================================================================