#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // =============================================================== using namespace std; using ll = long long; using vl = vector; using vll = vector>; using vs = vector; using vc = vector; using vcc = vector>; using vm = vector; using vmm = vector>; using pii = pair; using psi = pair; using ld = long double; using ull = unsigned long long; // =============================================================== ll gcd(ll a, ll b) //最大公約数 { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } } ll lcm(ll a, ll b) //最小公倍数 { return a * b / gcd(a, b); } ll box(double a) //doubleの切り捨て { ll b = a; return b; } ll fff(double a) //doubleの四捨五入 { ll b = a + 0.5; return b; } ll sum(ll n) { //整数sまでの合計 if (n == 0) { return 0; } int s = sum(n - 1); return s + n; } bool prime(ll num)//素数判定、primeならtrue,違うならfalse { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } // 素数である return true; } // =============================================================== int main() { ll n; cin >> n; vl a(n); vl b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } ll ca = 0; ll cb = 0; for (int i = 0; i < n; i++) { ca += a[i]; cb += b[i]; } ll count = 0; vl ja(n); for (int i = 0; i < n; i++) { ja[i] = b[i] - a[i]; } ll you = 0; bool hantei = false; sort(ja.begin(), ja.end()); ll ans = 0; for (int i = 0; i < n; i++) { ans = abs(ja[0]); you = ja[i] - ja[0]; count += you; } if (count >= ans*2) hantei = true; ll siagea = 0; ll siageb = 0; for (int i = 0; i < n; i++) { if (a[i] > b[i]) { siageb += a[i] - b[i]; } else { siagea += b[i] - a[i]; } } if (hantei) { cout << ans << endl; } else cout << -1 << endl; }