Hello sir,please review my code,help me for which test case it is failing
-----------------------------------------------------------------------------------------------------------------------
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Solution {
static int c[] = null, d[] = null;

public static void solve() {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int t = 0, n = 0, k = 0;
String data[] = null;
try {
result = 0;
t = Integer.parseInt(br.readLine());
for (int i = 1; i <= t; i++) {
data = br.readLine().split(" ");
n = Integer.parseInt(data[0]);
k = Integer.parseInt(data[1]);
c = new int[n];
d = new int[n];
data = br.readLine().split(" ");
for (int j = 0; j < n; j++) {
c[j] = Integer.parseInt(data[j]);
}
data = br.readLine().split(" ");
for (int j = 0; j < n; j++) {
d[j] = Integer.parseInt(data[j]);
}

Pair aux = new Pair();
aux.l = 0;
aux.r = n;
ArrayList<Pair> clist = new ArrayList<Pair>();
clist.add(aux);

aux = new Pair();
aux.l = 0;
aux.r = n;
ArrayList<Pair> dlist = new ArrayList<Pair>();
dlist.add(aux);
processWar(clist, k, n);
System.out.println("Case #" + i + ": " + result);
result = 0;
}

} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

static int result = 0;

public static void main(String[] args) {
solve();
}

public static void processWar(ArrayList<Pair> cswards, int k, int n) {
int len = 0;
int clen = cswards.size();
int start = 0, end = 0;
Pair csward = null, auxC = null, auxP = null;
ArrayList<Pair> cswards2 = new ArrayList<>();
ArrayList<Integer> cloactions = new ArrayList<Integer>();
ArrayList<Integer> dloactions = new ArrayList<Integer>();
int cCnt = 0, dCnt = 0;
for (int i = 0; i < clen; i++) {
csward = cswards.get(i);
cloactions.clear();
dloactions.clear();
cCnt = getMaxCnt_C(csward.l, csward.r, cloactions);
dCnt = getMaxCnt_D(csward.l, csward.r, dloactions);

if ((Math.abs(cCnt - dCnt)) <= k) {
result += (cloactions.size() * dloactions.size());
} else {
cloactions = dloactions;
}
start = csward.l;
end = csward.r;
len = cloactions.size();
if (len == 0) {
continue;
}
int j = 0;
auxP = null;
if (start == cloactions.get(0)) {
start++;
j++;
} else {
auxP = auxC = new Pair();
auxC.l = start;
auxC.r = cloactions.get(0);
start = cloactions.get(0)+1;
cswards2.add(auxC);
j++;
}
for (; j < len; j++) {
if (cloactions.get(j) - cloactions.get(j - 1) == 1) {
start=cloactions.get(j)+1;
continue;
}
if (start < cloactions.get(j) - 1) {
auxC = new Pair();
auxC.l = start;
auxC.r = cloactions.get(j);
start = cloactions.get(j) + 1;
if (auxP == null) {
auxP = auxC;
cswards2.add(auxC);
} else {
if (auxP.r == auxC.l) {
auxP.r = auxC.r;
} else {
cswards2.add(auxC);
}
}

}
}

if (!(start == csward.l && end == csward.r) && (cloactions.get(len - 1) + 1
< end)) {
if (start != end && start < end) {
auxC = new Pair();
auxC.l = start;
if (end != n) {
end++;
}
auxC.r = end;
cswards2.add(auxC);
}
}

}
if (cswards2.size() == 0) {
return;
}
processWar(cswards2, k, n);
}

public static int getMaxCnt_C(int l, int u, ArrayList<Integer> locations) {
int max = 0;
for (int i = l; i < u; i++) {
if (max < c[i]) {
locations.clear();
max = c[i];
locations.add(i);
continue;
}
if (max == c[i]) {
locations.add(i);
}
}
return max;
}

public static int getMaxCnt_D(int l, int u, ArrayList<Integer> locations) {
int max = 0;
for (int i = l; i < u; i++) {
if (max < d[i]) {
locations.clear();
max = d[i];
locations.add(i);
continue;
}
if (max == d[i]) {
locations.add(i);
}
}
return max;
}
}

class Pair {
int l = 0, r = 0;

public String toString() {
return l + "," + r;
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAN7RGWZv1hG6bQpKiGUGOO-vCZFAgO1uT8OrNufCzPUoB_P4UA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to