-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeputy Chef.cpp
42 lines (40 loc) · 954 Bytes
/
Deputy Chef.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define fastIO ios::sync_with_stdio(0); cin.tie(0);
int main()
{
fastIO
int t;
cin >> t;
while(t--)
{
int n;
cin>>n;
vector<int>a(n),d(n);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>d[i];
ll ans = INT_MIN;
if(d[0]>a[1] && d[0]>a[n-1] && (d[0]>(a[1]+a[n-1])))
{
if(d[0]>ans) ans = d[0];
}
for(int i=1;i<n;i++)
{
if(d[i]>a[(i+1)%n] && d[i]>a[i-1] && (d[i]>(a[(i+1)%n]+a[i-1])))
{
if(d[i]>ans) ans = d[i];
}
}
if(ans==INT_MIN) cout<<"-1\n";
else cout<<ans<<"\n";
}
return 0;
}