#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 2e5+10, MOD = 998244353;
const ll INF = 1e18+10;
void solve() {
int n, m, d; cin >> n >> m >> d;
vector<int> a(n); for (auto& x : a) cin >> x;
vector<int> b(m); for (auto& x : b) cin >> x;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
v.emplace_back(a[i], i);
}
for (int i = 0; i < m; i++) {
v.emplace_back(b[i], n + i);
}
sort(v.begin(), v.end());
vector<int> loc_a(n), loc_b(m);
for (int i = 0; i < n + m; i++) {
if (v[i].second < n) {
loc_a[v[i].second] = i;
} else {
loc_b[v[i].second - n] = i;
}
}
// end[i] = max(a[i] - t, end[i-1] + d)
// final condition: end[i] <= a[i] + t
//
// end[i] = max(a[i], end[i-1] + d)
// final condition: end[i] <= a[i] + 2 * t
//
// end[i] = max((i - j) * d + a[j])
// final conditoin: end[i] <= a[i] + 2 * t
// t = max((i - j) * d + a[j] - a[i]) / 2
// t = max((i * d - a[i] - (j * d - a[j])) / 2
// D * i - x
vector<ll> val(n + m);
vector<bool> on(n + m);
for (int i = 0; i < n; i++) {
val[loc_a[i]] = -a[i];
}
for (int i = 0; i < m; i++) {
val[loc_b[i]] = -b[i];
}
auto activate = [&](int i) {
for (int j = i + 1; j < n + m; j++) {
val[j] += d;
}
on[i] = 1;
};
for (int i = 0; i < n; i++) {
activate(loc_a[i]);
}
for (int i = 0; i < m; i++) {
activate(loc_b[i]);
ll ans = 0;
for (int x = 0; x < n + m; x++) if (on[x]) {
for (int y = x + 1; y < n + m; y++) if (on[y]) {
ans = max(ans, val[y] - val[x]);
}
}
cout << (long double) ans / 2 << ' ';
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
340 KB |
Output is correct |
2 |
Incorrect |
23 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
340 KB |
Output is correct |
2 |
Incorrect |
23 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1579 ms |
4944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1579 ms |
4944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |