// AUTHOR->DEV KUDAWLA
//----------------------------------------------------
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order(it return an iterator input is a value), order_of_key(input is index)
typedef tree<long long, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define ll long long int
#define vl vector<long long>
#define nline cout << "\n"
#define n_digit(n) (int)log10(n) + 1
#define msb(n) (int)(log2(n)) + 1
// it is 1 based
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define ternary(a, b, c) ((a) ? (b) : (c))
#define yesno(a) a ? cout << "Yes" : cout << "No"
#define sroot(a) sqrt((long double)a)
#define Max(a, b) max((ll)a, (ll)b)
#define Min(a, b) min((ll)a, (ll)b)
//----------------------------------------------------
template <class T1, class T2>
ostream &operator<<(std::ostream &os, pair<T1, T2> &st)
{
cout << "{ " << st.first << " " << st.second << " }";
return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v)
{
int n = v.size();
for (int i = 0; i < n; i++)
is >> v[i];
return is;
}
template <class T>
istream &operator>>(istream &is, vector<vector<T>> &v)
{
int n = v.size();
int m = v[0].size();
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
is >> v[i][j];
return is;
}
template <class T>
ostream &operator<<(std::ostream &os, vector<T> &v)
{
int n = v.size();
for (int i = 0; i < n; i++)
os << v[i] << ((i == n - 1) ? "\n" : " ");
return os;
}
template <class T>
ostream &operator<<(std::ostream &os, vector<vector<T>> &v)
{
int n = v.size();
int m = v[0].size();
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
os << v[i][j] << " ";
os << "\n";
}
return os;
}
template <class T>
ostream &operator<<(std::ostream &os, set<T> &st)
{
cout << "---------------------------------\n";
for (auto i : st)
cout << i << " ";
nline;
cout << "---------------------------------\n";
return os;
}
template <class T>
ostream &operator<<(std::ostream &os, multiset<T> &st)
{
cout << "---------------------------------\n";
for (auto i : st)
cout << i << " ";
nline;
cout << "---------------------------------\n";
return os;
}
template <class T1, class T2>
ostream &operator<<(std::ostream &os, map<T1, T2> &st)
{
cout << "-------------------------------\n";
auto x = st.begin();
while (x != st.end())
{
cout << x->first;
cout << " -> ";
cout << x->second;
nline;
x++;
}
cout << "-------------------------------\n";
return os;
}
template <class T>
vector<T> add(vector<T> v1, vector<T> v2)
{
vector<T> v3 = v1;
for (ll i = 0; i < v2.size(); i++)
v3.push_back(v2[i]);
return v3;
}
template <int D, typename T>
struct Vector : public vector<Vector<D - 1, T>>
{
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template <typename U, typename... Args>
Vector(U n = U(), Args... args) : vector<Vector<D - 1, T>>(n, Vector<D - 1, T>(args...)) {}
};
template <typename T>
struct Vector<1, T> : public vector<T>
{
template <typename... Args>
Vector(Args... args) : vector<T>(args...) {}
};
inline ll power2(ll n)
{
ll answer = 0;
if (n != 0)
answer = msb(((ll)n) ^ ((ll)(n - 1))) - 1;
return answer;
}
inline ll indexOf(ordered_multiset &st, ll value)
{
return st.order_of_key(value);
}
inline ll valueAt(ordered_multiset &st, ll index)
{
return *st.find_by_order(index);
}
inline ll indexOf(ordered_set &st, ll value)
{
return st.order_of_key(value);
}
inline ll valueAt(ordered_set &st, ll index)
{
return *st.find_by_order(index);
}
template <class T>
void Distinct(T &v, bool sorting = true)
{
if (sorting)
sort(begin(v), end(v));
v.resize(unique(begin(v), end(v)) - begin(v));
}
//----------------------------------------------------
const ll N1 = 1000000007;
const ll N2 = 998244353;
//----------------------------------------------------
// MODULAR ARITHMETIC
inline ll expo(ll a, ll b, ll mod = LONG_LONG_MAX)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = ((__int128_t)res * a) % mod;
a = ((__int128_t)a * a) % mod;
b = b >> 1;
}
return res;
}
inline ll mminvprime(ll a, ll b) { return expo(a, b - 2, b); } // FOR PRIME
inline ll mod_add(ll a, ll b, ll m = N1)
{
a = a % m;
b = b % m;
return (((a + b) % m) + m) % m;
}
inline ll mod_mul(ll a, ll b, ll m = N1)
{
a = a % m;
b = b % m;
return (((__int128_t)(a * b) % m) + m) % m;
}
inline ll mod_sub(ll a, ll b, ll m = N1)
{
a = a % m;
b = b % m;
return (((a - b) % m) + m) % m;
}
inline ll mod_div(ll a, ll b, ll m = N1)
{
a = a % m;
b = b % m;
return (mod_mul(a, mminvprime(b, m), m) + m) % m;
} // only for prime m
ll ncr(ll n, ll r, bool mod_version = false, ll mod = N1)
{
ll answer = 0;
if (n >= r)
{
r = Min(r, n - r);
if (mod_version == true)
{
ll a = 1;
for (ll i = n; i >= n - r + 1; i--)
a = mod_mul(a, i, mod);
ll b = 1;
for (ll i = 1; i <= r; i++)
b = mod_mul(b, i, mod);
b = mminvprime(b, mod);
a = mod_mul(a, b, mod);
answer = a;
}
else
{
ll a = 1;
ll b = 1;
for (ll i = n; i >= n - r + 1; i--)
{
a *= i;
b *= (n - i + 1);
ll g = __gcd(a, b);
a /= g, b /= g;
}
answer = a / b;
}
}
return answer;
}
ll factorial(ll n, bool mod_version = false, ll mod = N1)
{
ll answer = 1;
if (mod_version == true)
{
for (int i = 2; i <= n; i++)
answer = mod_mul(answer, i, mod);
}
else
{
for (int i = 2; i <= n; i++)
answer *= i;
}
return answer;
}
bool is_prime(ll a)
{
if (a == 1)
return false;
for (ll i = 2; i * i <= a; i++)
{
if (a % i == 0)
return false;
}
return true;
}
//----------------------------------------------------
map<ll, ll> prime_factors(ll n, bool debug = false)
{
map<ll, ll> answer;
ll a = n;
for (ll i = 2; i * i <= a; i++)
while (a % i == 0)
answer[i]++, a /= i;
if (a > 1)
answer[a]++;
if (debug)
{
for (auto i : answer)
cout << i.first << " -> " << i.second << "\n";
}
return answer;
}
//----------------------------------------------------
// const int n_sieve = (20000008); // O(Nlog(log(N)))
// vector<bool> prime_sieve(n_sieve + 1, true);
void initialise_sieve(vector<bool> &prime_sieve)
{
prime_sieve[0] = false;
prime_sieve[1] = false;
for (ll i = 2; i * i < prime_sieve.size(); i++)
if (prime_sieve[i] == true)
for (ll j = 2; j * i < prime_sieve.size(); j++)
prime_sieve[j * i] = false;
}
//----------------------------------------------------
// #define LOCAL_COMPILER
#ifdef LOCAL_COMPILER
#define dbg(x) \
cerr << #x << " -> "; \
cout << x << "\n";
#endif
#ifndef LOCAL_COMPILER
#define dbg(x)
#endif
//----------------------------------------------------
// CODE STARTS HERE
//----------------------------------------------------
void solve(bool testCases = true)
{
ll T = 1; //->TEST CASES
if (testCases)
cin >> T;
while (T--)
{
ll n;
cin >> n;
vector<pll> v(n + 1);
for (ll i = 0; i < n + 1; i++)
{
ll d;
cin >> d;
v[i] = {d, i + 1};
}
sort(all(v));
dbg(v);
vl b(n);
cin >> b;
sort(all(b));
dbg(b);
vl answer(n + 2, 0);
multiset<ll> st;
for (ll i = 0; i < n; i++)
st.insert(Max(0, v[i].first - b[i]));
ll index = n;
answer[v[index].second] = *--st.end();
dbg(answer);
for (ll i = n - 1; i >= 0; i--)
{
ll d = Max(0, v[i].first - b[i]);
st.erase(st.find(d));
d = Max(0, v[index].first - b[i]);
st.insert(d);
answer[v[i].second] = *--st.end();
index = i;
}
for (ll i = 1; i <= n + 1; i++)
cout << answer[i] << " ";
nline;
}
//--------------------------------------------
// CODE ENDS HERE
}
//----------------------------------------------------
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//------------------------------------------------
// initialise_sieve(prime_sieve);
//------------------------------------------------
#ifdef LOCAL_COMPILER
std::cout << std::fixed << std::setprecision(25);
std::cerr << std::fixed << std::setprecision(10);
auto start = std::chrono::high_resolution_clock::now();
#endif
solve(false);
#ifdef LOCAL_COMPILER
auto stop = std::chrono::high_resolution_clock::now();
long double duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start).count();
std::cerr << "Time taken : " << duration / 1e9 << "s" << std::endl;
#endif
//------------------------------------------------
return 0;
}
//----------------------------------------------------
Compilation message
ho_t1.cpp: In function 'void initialise_sieve(std::vector<bool>&)':
ho_t1.cpp:286:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
286 | for (ll j = 2; j * i < prime_sieve.size(); j++)
| ~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
612 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
520 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
520 KB |
Output is correct |
26 |
Correct |
1 ms |
520 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
608 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
612 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
520 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
520 KB |
Output is correct |
26 |
Correct |
1 ms |
520 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
608 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
143 ms |
20376 KB |
Output is correct |
34 |
Correct |
160 ms |
21368 KB |
Output is correct |
35 |
Correct |
144 ms |
20460 KB |
Output is correct |
36 |
Correct |
155 ms |
21004 KB |
Output is correct |
37 |
Correct |
165 ms |
21880 KB |
Output is correct |
38 |
Correct |
150 ms |
21420 KB |
Output is correct |
39 |
Correct |
176 ms |
20472 KB |
Output is correct |
40 |
Correct |
178 ms |
20468 KB |
Output is correct |
41 |
Correct |
176 ms |
20600 KB |
Output is correct |
42 |
Correct |
176 ms |
20412 KB |
Output is correct |
43 |
Correct |
169 ms |
20304 KB |
Output is correct |
44 |
Correct |
140 ms |
19848 KB |
Output is correct |
45 |
Correct |
138 ms |
19928 KB |
Output is correct |
46 |
Correct |
139 ms |
19788 KB |
Output is correct |
47 |
Correct |
118 ms |
20344 KB |
Output is correct |
48 |
Correct |
136 ms |
20560 KB |
Output is correct |
49 |
Correct |
186 ms |
21156 KB |
Output is correct |
50 |
Correct |
188 ms |
21032 KB |
Output is correct |
51 |
Correct |
188 ms |
20996 KB |
Output is correct |
52 |
Correct |
192 ms |
21096 KB |
Output is correct |
53 |
Correct |
198 ms |
21000 KB |
Output is correct |