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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <bits/stdc++.h> #define all(vec) vec.begin(),vec.end() #define CLR(i,a) memset(i,a,sizeof(i)) #define pb push_back #define SZ(a) ((int) a.size()) #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define ROF(i, a, b) for (int i = (a); i >= (b); --i) #define debug(var) cerr << #var <<":"<<var<<"\n"; #define lson(var) (var<<1) #define rson(var) ((var<<1)+1)
using namespace std;
typedef long long ll;typedef unsigned long long ull; typedef double DB;typedef long double LD; typedef __int128 i128;typedef pair<DB,DB> pdd;typedef pair<ll,bool> plb; typedef pair<ll,ll> pll; typedef array<ll,3> arr3;typedef array<ll,2> arr2; constexpr ll MAXN=static_cast<ll>(1e6)+10,INF=static_cast<ll>(1e9)+9; constexpr ll mod=static_cast<ll>(1e9)+7; constexpr double eps=1e-8;
ll N,M,Q,X,K,lT,A[MAXN],B[MAXN],up[MAXN];
inline void init(){ } inline void solve(){ cin>>N; init(); ll mxA=0; FOR(i,1,N){ cin>>A[i]; mxA=max(A[i],mxA); } ll sumb=0; FOR(i,1,N){ cin>>B[i]; sumb+=B[i]; } ll l=mxA,r=4e9; #ifdef LOCAL debug(mxA); debug(sumb); debug(r); debug(B[15]); #endif auto check=[&](ll mid){ ll rem=0;ll nee=0; FOR(i,1,N){ if(A[i]+B[i]<=mid){ ll diff=mid-A[i]-B[i]; rem+=diff/2; }else{ nee+=B[i]-(mid-A[i]); } } #ifdef LOCAL debug(mid); debug(nee); debug(rem); #endif if(nee>rem){ return false; }else{ return true; } }; while(l<r){ ll mid=l+r>>1; #ifdef LOCAL debug(mid); #endif if(check(mid)){ r=mid; }else{ l=mid+1; } } cout<<l<<"\n"; }
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>lT; while(lT--){ solve(); } return 0; }
|