fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int n;
  9. if (!(cin >> n)) return 0;
  10.  
  11. vector<long long> a(n);
  12. for (int i = 0; i < n; ++i) cin >> a[i];
  13.  
  14. long long s = 0, ans = 0;
  15. for (int i = 0; i < n; ++i) {
  16. long long b;
  17. cin >> b;
  18. s += a[i] - b; // s_i
  19. ans = max(ans, llabs(s)); // i = 1..n-1; s_n = 0 nên không ảnh hưởng
  20. }
  21. cout << ans << '\n';
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 5284KB
stdin
4
3 10 8 2
4 6 10 3
stdout
3