Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //
- #define ll long long
- #define ull unsigned long long
- #define mx 100010
- #define mod 1000000007
- #define inf INT_MAX
- #define pi acos(-1.0)
- #define endl '\n'
- #define pb push_back
- #define pll pair<ll, ll>
- #define vll vector<ll>
- #define vpll vector<pll>
- #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- //
- int main() {
- ll t;
- cin >> t;
- while (t--) {
- ll n;
- cin >> n;
- ll end[n], begin[n];
- for (ll i = 0; i < n; i++) cin >> end[i];
- for (ll i = 0; i < n; i++) {
- ll a;
- cin >> a;
- begin[i] = end[i] - a + 1;
- }
- ll first = begin[n - 1], second = end[n - 1];
- //cout << first << " " << second << endl; //!
- ull tot = 0;
- for (ll i = n - 2; i >= 0; i--) {
- if (first <= end[i]) first = min(first, begin[i]);
- else {
- ll temp = second - first + 1;
- tot += (temp * (temp + 1)) / 2;
- first = begin[i], second = end[i];
- }
- }
- tot += ((second - first + 1) * (second - first + 2)) / 2;
- cout << tot << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement