Modern Cpp

#include <iostream>
#include <vector>
#include <numeric>

using i64 = long long;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);

  int n;
  std::cin >> n;

  std::vector<int> a(n + 1), b(n + 1);
  for(int i = 1; i <= n; i++){
    std::cin >> a[i];
  }
  for(int i = 1; i <= n; i++){
    std::cin >> b[i];
  }

  i64 suma = std::accumulate(a.begin(), a.end(), 0LL);
  i64 sumb = std::accumulate(b.begin(), b.end(), 0LL);

  if(suma ^ sumb){
    std::cout << "-1\n";
    return 0;
  }

  i64 ans = 0;
  for(int i = 1; i <= n; i++){
    if(a[i] < b[i]){
      ans += b[i] - a[i];
    }
  }

  std::cout << ans << "\n";

  return 0;
}