#include <algorithm>
#include <fstream>
#include <iostream>
#include <limits>
#include <unordered_map>
#include <vector>
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
typedef unsigned short u16;
typedef short i16;
typedef unsigned int u32;
typedef int i32;
typedef unsigned long long u64;
typedef long long i64;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef long double f128;
namespace std
{
template <typename T, typename U>
struct hash<pair<T, U>>
{
size_t operator()(const pair<T, U>& x) const { return hash<T>()(x.first) ^ hash<U>()(x.second); }
};
} // namespace std
template <typename T>
using limits = std::numeric_limits<T>;
template <typename T, typename U>
using pa = std::pair<T, U>;
template <typename T, typename U>
using umap = std::unordered_map<T, U>;
#ifdef LOCAL
#include <chrono>
#include "tools.hpp"
#define here(...) \
std::cerr << __func__ << ':' << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; \
_debug(__VA_ARGS__)
#else
#define here(...)
#endif
void solve()
{
u32 n;
std::cin >> n;
std::vector<u32> id(n + 1);
std::vector<i32> b(n), pr(n + 1), sf(n + 1);
std::vector<std::pair<i32, u32>> c(n + 1);
for (u32 i = 0; i < n + 1; ++i)
{
i32 ai;
std::cin >> ai;
c[i] = std::make_pair(ai, i);
}
for (auto& i : b)
{
std::cin >> i;
}
std::sort(b.begin(), b.end());
std::sort(c.begin(), c.end());
for (u32 i = 0; i < n + 1; ++i)
{
id[c[i].second] = i;
}
for (u32 i = 0; i < n + 1; ++i)
{
pr[i] = std::max(i > 0 ? pr[i - 1] : 0, c[i].first - (i < n ? b[i] : 0));
}
for (u32 i = n; i + 1 > 0; i--)
{
sf[i] = std::max(i < n ? sf[i + 1] : 0, c[i].first - (i > 0 ? b[i - 1] : 0));
}
for (auto& i : id)
{
std::cout << std::max(i > 0 ? pr[i - 1] : 0, i < n ? sf[i + 1] : 0) << ' ';
}
std::cout << '\n';
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
#ifdef LOCAL
using std::chrono::duration_cast;
using std::chrono::high_resolution_clock;
using std::chrono::microseconds;
auto st = high_resolution_clock::now();
std::ifstream input("./in.txt");
std::ofstream output("./log/bsol.txt");
auto cin_buf = std::cin.rdbuf(input.rdbuf());
auto cout_buf = std::cout.rdbuf(output.rdbuf());
#endif
solve();
#ifdef LOCAL
std::cin.rdbuf(cin_buf);
std::cout.rdbuf(cout_buf);
input.close();
output.close();
auto ed = high_resolution_clock::now();
std::cerr << "Time elapsed: " << duration_cast<microseconds>(ed - st).count() << " microseconds\n";
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
69 ms |
6204 KB |
Output is correct |
34 |
Correct |
75 ms |
6512 KB |
Output is correct |
35 |
Correct |
70 ms |
6372 KB |
Output is correct |
36 |
Correct |
71 ms |
6788 KB |
Output is correct |
37 |
Correct |
85 ms |
6932 KB |
Output is correct |
38 |
Correct |
81 ms |
6868 KB |
Output is correct |
39 |
Correct |
70 ms |
5908 KB |
Output is correct |
40 |
Correct |
70 ms |
6032 KB |
Output is correct |
41 |
Correct |
87 ms |
5976 KB |
Output is correct |
42 |
Correct |
70 ms |
6060 KB |
Output is correct |
43 |
Correct |
69 ms |
5912 KB |
Output is correct |
44 |
Correct |
72 ms |
5572 KB |
Output is correct |
45 |
Correct |
69 ms |
5744 KB |
Output is correct |
46 |
Correct |
76 ms |
5812 KB |
Output is correct |
47 |
Correct |
65 ms |
5532 KB |
Output is correct |
48 |
Correct |
65 ms |
5544 KB |
Output is correct |
49 |
Correct |
72 ms |
6104 KB |
Output is correct |
50 |
Correct |
77 ms |
6180 KB |
Output is correct |
51 |
Correct |
71 ms |
6168 KB |
Output is correct |
52 |
Correct |
71 ms |
6172 KB |
Output is correct |
53 |
Correct |
75 ms |
6196 KB |
Output is correct |