-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDEPCHEF.java
45 lines (40 loc) · 1.21 KB
/
DEPCHEF.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.codechef;
import java.util.*;
import java.lang.*;
class DEPCHEF
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int a =0 ; a< T ; a++){
int N = sc.nextInt();
int[] attack =new int[N+2];
int[] defence =new int[N+2];
for(int i = 1; i<N+1 ; i++){
attack[i] = sc.nextInt();
}
attack[0] = attack[N];
attack[N+1] = attack[1];
for(int j = 1; j< N+1 ; j++){
defence[j] = sc.nextInt();
}
defence[0] = defence[N];
defence[N+1] = defence[1];
int best_def = 0;
for(int k = 1 ; k< N+1 ; k++){
if(defence[k] > (attack[k-1] + attack[k+1])){
if(best_def< defence[k]){
best_def = defence[k];
}
}
}
if(best_def != 0){
System.out.println(best_def);
}
else{
System.out.println("-1");
}
}
}
}