#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

template <typename T>
class FenwickTree {
	const int n;
	vector<T> data;
public:
	FenwickTree(int n) : n(n), data(n, 0) {}
	void add(int i, T value) {
		for (; i < n; i |= i + 1) data[i] += value;
	}
	T sum(int i) {
		T s = 0;
		for (; i >= 0; i = (i&(i + 1)) - 1) s += data[i];
		return s;
	}
};

int main()
{
	int n; cin >> n;
	vector<pii> to(n + 1);
	vi l(n);
	ll sum = 0;
	REP(i, n)
	{
		int a; cin >> a;
		sum += a;
		to[i + 1] = pii(sum, i);
	}
	REP(i, n) cin >> l[i];
	sort(ALL(to));
	REP(i, n)
	{
		if (to[i + 1].first- to[i].first < l[i])
		{
			cout << -1 << endl;
			return 0;
		}
	}
	FenwickTree<ll> bit(n);
	ll ans = 0;
	FOR(i, 1, n + 1)
	{
		ans += i - bit.sum(to[i].second) - 1;
		bit.add(to[i].second, 1);
	}
	cout << ans << endl;
}