#include <bits/stdc++.h>
#define ll long long
#define ii pair <int, int>
#define F first
#define S second
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a[N], b[N];
void solve(){
cin >> n;
ll ans = 0;
int mx = 0;
set <ii> s;
s.insert(ii(-2e9, -2e9));
s.insert(ii(2e9, 2e9));
for (int i = 1; i <= n; ++ i) cin >> a[i];
for (int i = 1; i <= n; ++ i){
cin >> b[i];
ans += (a[i] - b[i]);
int l = b[i], r = a[i];
ii st = *(--s.upper_bound(ii(b[i], b[i])));
if (st.S >= b[i]){
l = min(l, st.F);
s.erase(s.lower_bound(st));
r = max(r, st.S);
}
while (true){
ii ed = *s.lower_bound(ii(b[i], b[i]));
if (ed.F > a[i]) break;
r = max(r, ed.S);
l = min(l, ed.F);
s.erase(s.lower_bound(ed));
}
s.insert(ii(l, r));
mx = max(mx, r - l);
cout << ans - mx << ' ';
}
cout << '\n';
}
int main(){
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t --) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgaWkgcGFpciA8aW50LCBpbnQ+CiNkZWZpbmUgRiBmaXJzdAojZGVmaW5lIFMgc2Vjb25kCiNkZWZpbmUgcGIgcHVzaF9iYWNrCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE4gPSAyZTUgKyA1Owpjb25zdCBpbnQgbW9kID0gMWU5ICsgNzsKCmludCBuLCBhW05dLCBiW05dOwoKdm9pZCBzb2x2ZSgpewogICAgY2luID4+IG47CiAgICBsbCBhbnMgPSAwOwogICAgaW50IG14ID0gMDsKICAgIHNldCA8aWk+IHM7CiAgICBzLmluc2VydChpaSgtMmU5LCAtMmU5KSk7CiAgICBzLmluc2VydChpaSgyZTksIDJlOSkpOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKysgaSkgY2luID4+IGFbaV07CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArKyBpKXsKICAgICAgICBjaW4gPj4gYltpXTsKICAgICAgICBhbnMgKz0gKGFbaV0gLSBiW2ldKTsKCiAgICAgICAgaW50IGwgPSBiW2ldLCByID0gYVtpXTsKCiAgICAgICAgaWkgc3QgPSAqKC0tcy51cHBlcl9ib3VuZChpaShiW2ldLCBiW2ldKSkpOwogICAgICAgIGlmIChzdC5TID49IGJbaV0pewogICAgICAgICAgICBsID0gbWluKGwsIHN0LkYpOwogICAgICAgICAgICBzLmVyYXNlKHMubG93ZXJfYm91bmQoc3QpKTsKICAgICAgICAgICAgciA9IG1heChyLCBzdC5TKTsKICAgICAgICB9CgogICAgICAgIHdoaWxlICh0cnVlKXsKICAgICAgICAgICAgaWkgZWQgPSAqcy5sb3dlcl9ib3VuZChpaShiW2ldLCBiW2ldKSk7CiAgICAgICAgICAgIGlmIChlZC5GID4gYVtpXSkgYnJlYWs7CiAgICAgICAgICAgIHIgPSBtYXgociwgZWQuUyk7CiAgICAgICAgICAgIGwgPSBtaW4obCwgZWQuRik7CiAgICAgICAgICAgIHMuZXJhc2Uocy5sb3dlcl9ib3VuZChlZCkpOwogICAgICAgIH0KICAgICAgICBzLmluc2VydChpaShsLCByKSk7CiAgICAgICAgbXggPSBtYXgobXgsIHIgLSBsKTsKICAgICAgICBjb3V0IDw8IGFucyAtIG14IDw8ICcgJzsKICAgIH0KCiAgICBjb3V0IDw8ICdcbic7Cn0KCmludCBtYWluKCl7Ci8vICAgIGZyZW9wZW4oIi5pbnAiLCAiciIsIHN0ZGluKTsKLy8gICAgZnJlb3BlbigiLm91dCIsICJ3Iiwgc3Rkb3V0KTsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgY291dC50aWUoMCk7CiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUgKHQgLS0pIHNvbHZlKCk7CgogICAgcmV0dXJuIDA7Cn0K
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
^
Main.java:2: error: illegal character: '#'
#define ll long long
^
Main.java:3: error: illegal character: '#'
#define ii pair <int, int>
^
Main.java:4: error: illegal character: '#'
#define F first
^
Main.java:5: error: illegal character: '#'
#define S second
^
Main.java:6: error: illegal character: '#'
#define pb push_back
^
Main.java:10: error: class, interface, or enum expected
const int N = 2e5 + 5;
^
Main.java:11: error: class, interface, or enum expected
const int mod = 1e9 + 7;
^
Main.java:13: error: class, interface, or enum expected
int n, a[N], b[N];
^
Main.java:15: error: class, interface, or enum expected
void solve(){
^
Main.java:17: error: class, interface, or enum expected
ll ans = 0;
^
Main.java:18: error: class, interface, or enum expected
int mx = 0;
^
Main.java:19: error: class, interface, or enum expected
set <ii> s;
^
Main.java:20: error: class, interface, or enum expected
s.insert(ii(-2e9, -2e9));
^
Main.java:21: error: class, interface, or enum expected
s.insert(ii(2e9, 2e9));
^
Main.java:22: error: class, interface, or enum expected
for (int i = 1; i <= n; ++ i) cin >> a[i];
^
Main.java:22: error: class, interface, or enum expected
for (int i = 1; i <= n; ++ i) cin >> a[i];
^
Main.java:22: error: class, interface, or enum expected
for (int i = 1; i <= n; ++ i) cin >> a[i];
^
Main.java:23: error: class, interface, or enum expected
for (int i = 1; i <= n; ++ i){
^
Main.java:23: error: class, interface, or enum expected
for (int i = 1; i <= n; ++ i){
^
Main.java:23: error: class, interface, or enum expected
for (int i = 1; i <= n; ++ i){
^
Main.java:25: error: class, interface, or enum expected
ans += (a[i] - b[i]);
^
Main.java:27: error: class, interface, or enum expected
int l = b[i], r = a[i];
^
Main.java:29: error: class, interface, or enum expected
ii st = *(--s.upper_bound(ii(b[i], b[i])));
^
Main.java:30: error: class, interface, or enum expected
if (st.S >= b[i]){
^
Main.java:32: error: class, interface, or enum expected
s.erase(s.lower_bound(st));
^
Main.java:33: error: class, interface, or enum expected
r = max(r, st.S);
^
Main.java:34: error: class, interface, or enum expected
}
^
Main.java:38: error: class, interface, or enum expected
if (ed.F > a[i]) break;
^
Main.java:39: error: class, interface, or enum expected
r = max(r, ed.S);
^
Main.java:40: error: class, interface, or enum expected
l = min(l, ed.F);
^
Main.java:41: error: class, interface, or enum expected
s.erase(s.lower_bound(ed));
^
Main.java:42: error: class, interface, or enum expected
}
^
Main.java:44: error: class, interface, or enum expected
mx = max(mx, r - l);
^
Main.java:45: error: class, interface, or enum expected
cout << ans - mx << ' ';
^
Main.java:46: error: class, interface, or enum expected
}
^
Main.java:49: error: class, interface, or enum expected
}
^
Main.java:55: error: class, interface, or enum expected
cin.tie(0);
^
Main.java:56: error: class, interface, or enum expected
cout.tie(0);
^
Main.java:57: error: class, interface, or enum expected
int t;
^
Main.java:58: error: class, interface, or enum expected
cin >> t;
^
Main.java:59: error: class, interface, or enum expected
while (t --) solve();
^
Main.java:61: error: class, interface, or enum expected
return 0;
^
Main.java:62: error: class, interface, or enum expected
}
^
45 errors