Advertisement
fahad005

Untitled

Jan 22nd, 2022
866
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define mx 100010
  7. #define mod 1000000007
  8. #define inf INT_MAX
  9. #define pi acos(-1.0)
  10. #define endl '\n'
  11. #define pb push_back
  12. #define pll pair<ll, ll>
  13. #define vll vector<ll>
  14. #define vpll vector<pll>
  15. #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  16. //
  17. int main() {
  18.     ll t;
  19.     cin >> t;
  20.     while (t--) {
  21.         ll n;
  22.         cin >> n;
  23.         ll end[n], begin[n];
  24.         for (ll i = 0; i < n; i++) cin >> end[i];
  25.         for (ll i = 0; i < n; i++) {
  26.             ll a;
  27.             cin >> a;
  28.             begin[i] = end[i] - a + 1;
  29.         }
  30.         ll first = begin[n - 1], second = end[n - 1];
  31.         //cout << first << " " << second << endl; //!
  32.         ull tot = 0;
  33.         for (ll i = n - 2; i >= 0; i--) {
  34.             if (first <= end[i]) first = min(first, begin[i]);
  35.             else {
  36.                 ll temp = second - first + 1;
  37.                 tot += (temp * (temp + 1)) / 2;
  38.                 first = begin[i], second = end[i];
  39.             }
  40.         }
  41.         tot += ((second - first + 1) * (second - first + 2)) / 2;
  42.         cout << tot << endl;
  43.     }
  44. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement