fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Speed
  5. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6.  
  7. // Typedefs
  8. #define int long long
  9. #define pb push_back
  10. #define ff first
  11. #define ss second
  12. #define all(x) (x).begin(), (x).end()
  13. #define rall(x) (x).rbegin(), (x).rend()
  14. #define sz(x) ((int)(x).size())
  15. #define endl '\n'
  16.  
  17. // Loops
  18. #define rep(i,a,b) for(int i=a;i<b;++i)
  19. #define each(x, a) for (auto &x : a)
  20.  
  21. void solve() {
  22. int n;
  23. cin>>n;
  24. vector<int> a(n);
  25. vector<int> b(n);
  26. rep(i,0,n) cin>>a[i];
  27. rep(i,0,n) cin>>b[i];
  28. int sum=0;
  29. rep(i,0,n){
  30. sum=sum+max(sum-a[i],b[i]-sum);
  31. }
  32. cout<<sum<<endl;
  33. }
  34.  
  35. int32_t main() {
  36. fast_io;
  37. int t;
  38. cin >> t;
  39. while (t--) solve();
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 5316KB
stdin
3
3
4 -8 -1
-3 -7 0
5
-3 1 0 7 1
-5 3 -1 4 -5
5
-7 7 5 4 9
-9 -3 3 2 2
stdout
5
25
19