Source Code
#include <bits/stdc++.h>
using namespace std;
    
int main (){

  #ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1","r",stdin);
  #endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  long long sum = 0, ans = n - 1 + accumulate(a, a + n, 0LL);
  int last = 0;
  for (int i = 0; i < n; ++i) {
    sum += b[i];
    if (sum < a[i]) {
      ans += n - i - 1;
      break;
    }
    sum -= a[i];
  }
  cout << (accumulate(a, a + n, 0LL) > accumulate(b, b + n, 0LL) ? -1 : ans);

  return 0;
}
Copy
Shooting Balloons SuhaibSawalha1
GNU G++17
41 ms
3.2 MB
Wrong Answer