CHEFELEC ,WA is wrong judgement

chefelec
is
judgement
wa
wrong

#1

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) {
     }
    

    }
    }

====================================================================================


#2

Hello please let me know what wrong in this code


#3

Hello Below is the code that got the 100 points
Both my code and this code working same

========================================================================================================
package cook;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.;
class CHEFELEC {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t–>0)
{
long n = Long.parseLong(br.readLine()),sum=0;
int i;
long a[]=new long[100005];
String s1=br.readLine();
String s2=br.readLine();
StringTokenizer st=new StringTokenizer(s2);
for(i=0;i<n;i++)
{
a
=Long.parseLong(st.nextToken());
}
for(i=0;i<n;i++)
{
Character c=s1.charAt(i);
if(c.equals(‘1’))
{
sum=a*-a[0];break;
}
}
long last=a*,max=0;
for(++i;i<n;i++)
{
if(a*-a[i-1]>max)
max=a*-a[i-1];
Character c=s1.charAt(i);
if(c.equals(‘1’))
{
Character c1=s1.charAt(i-1);
if(c1.equals(‘0’))
{
sum+=a*-last-max;
}
last=a*;max=0;
}
}
// System.out.println(sum);
sum+=a[i-1]-last;
System.out.println(sum);
}
}
}