voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n; cin >> n; vector<int> a(n), d(n); for (auto& i: a) cin >> i; for (auto& i: d) cin >> i; map<int, pair<int, int>> mp; for (int i = 0; i < n; ++i) mp[i] = {a[i], d[i]}; auto check = [&](map<int, pair<int, int>>::iterator& cur) { int cost = 0; if (cur != mp.begin()) { --cur; cost += cur->second.first; ++cur; } ++cur; if (cur != mp.end()) cost += cur->second.first; --cur;
return cost > cur->second.second; };
set<int> s[2]; for (auto iter = mp.begin(); iter != mp.end(); ++iter) if (check(iter)) s[0].insert(iter->first); int cur = 0, nxt = 1, tot = 0; vector ans(n, 0); while (!s[cur].empty()) { for (constint& c: s[cur]) { ++ans[tot]; mp.erase(c); } for (constint& c: s[cur]) { auto iter = mp.upper_bound(c); if (iter != mp.end()) if (check(iter)) s[nxt].insert(iter->first); if (iter != mp.begin()) { --iter; if (check(iter)) s[nxt].insert(iter->first); } } s[cur].clear(); swap(cur, nxt); ++tot; } for (int i = 0; i < n; ++i) cout << ans[i] << " \n"[i == n - 1]; } }