Tokitsukaze and a+b=n (medium)

发布于 13 天前  0 次阅读


#include <bits/stdc++.h>

#define int long long
using namespace std;
const int N = 1e5 + 5;
int t, n, l1, r1, l2, r2;

signed main() {
    cin >> t;
    while (t--) {
        cin >> n >> l1 >> r1 >> l2 >> r2;
        if (n < l1 + l2 || n > r1 + r2) {
            cout << 0 << endl;
        } else {
            cout << abs(max(l1, n - r2) - min(n - l2, r1)) + 1 << endl;
        }
    }
    return 0;
}