#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
#define ff first
#define ss second
#define ll long long
const int MX = 2e5 + 15;
int n, m, d;
int a[MX], b[MX], ord[MX];
int cur;
pair<int, int> c[MX];
set<int> s;
struct T{
ll mn, lmn, rmn, sum;
T() {
sum = mn = lmn = rmn = 0;
}
} tree[4 * MX];
void update(int id, int l, int r, int pos, int x) {
if(r < pos || l > pos) return;
if(l == r) {
tree[id].mn = x;
tree[id].lmn = x;
tree[id].rmn = x;
tree[id].sum = x;
return;
}
int mid = (l + r) / 2;
update(id * 2 + 1, l, mid, pos, x);
update(id * 2 + 2, mid + 1, r, pos, x);
tree[id].mn = min(min(tree[id * 2 + 1].mn, tree[id * 2 + 2].mn), tree[id * 2 + 1].rmn + tree[id * 2 + 2].lmn);
tree[id].lmn = min(tree[id * 2 + 1].lmn, tree[id * 2 + 1].sum + tree[id * 2 + 2].lmn);
tree[id].rmn = min(tree[id * 2 + 2].rmn, tree[id * 2 + 2].sum + tree[id * 2 + 1].rmn);
tree[id].sum = tree[id * 2 + 1].sum + tree[id * 2 + 2].sum;
}
void go() {
for(int j = 0; j < m; j++) {
int ind = -1;
for(int i = 0; i < n; i++) {
if(a[i] > b[j]) {
ind = i;
break;
}
}
if(ind == -1) ind = n;
for(int i = n; i > ind; i--) a[i] = a[i - 1];
a[ind] = b[j];
n++;
ll mx = 0, mn = 1e18, cur = 0;
for(int i = 0; i < n - 1; i++) {
cur += a[i + 1] - a[i] - d;
mn = min(mn, cur - mx);
mx = max(mx, cur);
}
if(mn > 0) cout << "0\n";
else{
cout << -mn / 2;
if(mn % 2)cout << ".5\n";
else cout << "\n";
}
}
}
int main() {
cin >> n >> m >> d;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) {
cin >> b[i];
c[i] = {b[i], i};
}
sort(a, a + n);
if(n != 0) {
go();
return 0;
}
sort(c, c + m);
for(int i = 0; i < m; i++) ord[c[i].ss] = i;
for(int i = 0; i < m; i++) {
auto it = s.lower_bound(ord[i]);
if(it != s.begin()) {
it--;
update(0, 0, m - 1, ord[i], b[i] - c[*it].ff - d);
it++;
}
if(it != s.end()) {
update(0, 0, m - 1, *it, c[*it].ff - b[i] - d);
}
s.insert(ord[i]);
if(tree[0].mn > 0) cout << "0 ";
else{
cout << -tree[0].mn / 2;
if(tree[0].mn % 2) cout << ".5 ";
else cout << " ";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
25368 KB |
Output is correct |
2 |
Correct |
11 ms |
25332 KB |
Output is correct |
3 |
Correct |
13 ms |
25256 KB |
Output is correct |
4 |
Correct |
10 ms |
25320 KB |
Output is correct |
5 |
Correct |
11 ms |
25272 KB |
Output is correct |
6 |
Correct |
14 ms |
25312 KB |
Output is correct |
7 |
Correct |
10 ms |
25260 KB |
Output is correct |
8 |
Correct |
10 ms |
25276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
25368 KB |
Output is correct |
2 |
Correct |
11 ms |
25332 KB |
Output is correct |
3 |
Correct |
13 ms |
25256 KB |
Output is correct |
4 |
Correct |
10 ms |
25320 KB |
Output is correct |
5 |
Correct |
11 ms |
25272 KB |
Output is correct |
6 |
Correct |
14 ms |
25312 KB |
Output is correct |
7 |
Correct |
10 ms |
25260 KB |
Output is correct |
8 |
Correct |
10 ms |
25276 KB |
Output is correct |
9 |
Correct |
80 ms |
26016 KB |
Output is correct |
10 |
Correct |
75 ms |
26080 KB |
Output is correct |
11 |
Correct |
67 ms |
26052 KB |
Output is correct |
12 |
Correct |
91 ms |
26060 KB |
Output is correct |
13 |
Correct |
59 ms |
26028 KB |
Output is correct |
14 |
Correct |
73 ms |
26040 KB |
Output is correct |
15 |
Correct |
64 ms |
26072 KB |
Output is correct |
16 |
Correct |
72 ms |
26068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
38820 KB |
Output is correct |
2 |
Correct |
170 ms |
40728 KB |
Output is correct |
3 |
Correct |
172 ms |
40792 KB |
Output is correct |
4 |
Correct |
188 ms |
38652 KB |
Output is correct |
5 |
Correct |
190 ms |
39816 KB |
Output is correct |
6 |
Correct |
187 ms |
39028 KB |
Output is correct |
7 |
Correct |
186 ms |
39948 KB |
Output is correct |
8 |
Correct |
195 ms |
38644 KB |
Output is correct |
9 |
Correct |
182 ms |
38568 KB |
Output is correct |
10 |
Correct |
188 ms |
41048 KB |
Output is correct |
11 |
Correct |
176 ms |
39368 KB |
Output is correct |
12 |
Correct |
208 ms |
40428 KB |
Output is correct |
13 |
Correct |
174 ms |
38644 KB |
Output is correct |
14 |
Correct |
190 ms |
40592 KB |
Output is correct |
15 |
Correct |
187 ms |
40444 KB |
Output is correct |
16 |
Correct |
190 ms |
38552 KB |
Output is correct |
17 |
Correct |
183 ms |
39908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
38820 KB |
Output is correct |
2 |
Correct |
170 ms |
40728 KB |
Output is correct |
3 |
Correct |
172 ms |
40792 KB |
Output is correct |
4 |
Correct |
188 ms |
38652 KB |
Output is correct |
5 |
Correct |
190 ms |
39816 KB |
Output is correct |
6 |
Correct |
187 ms |
39028 KB |
Output is correct |
7 |
Correct |
186 ms |
39948 KB |
Output is correct |
8 |
Correct |
195 ms |
38644 KB |
Output is correct |
9 |
Correct |
182 ms |
38568 KB |
Output is correct |
10 |
Correct |
188 ms |
41048 KB |
Output is correct |
11 |
Correct |
176 ms |
39368 KB |
Output is correct |
12 |
Correct |
208 ms |
40428 KB |
Output is correct |
13 |
Correct |
174 ms |
38644 KB |
Output is correct |
14 |
Correct |
190 ms |
40592 KB |
Output is correct |
15 |
Correct |
187 ms |
40444 KB |
Output is correct |
16 |
Correct |
190 ms |
38552 KB |
Output is correct |
17 |
Correct |
183 ms |
39908 KB |
Output is correct |
18 |
Correct |
345 ms |
39052 KB |
Output is correct |
19 |
Correct |
389 ms |
40736 KB |
Output is correct |
20 |
Correct |
213 ms |
40700 KB |
Output is correct |
21 |
Correct |
241 ms |
38772 KB |
Output is correct |
22 |
Correct |
293 ms |
39128 KB |
Output is correct |
23 |
Correct |
229 ms |
38936 KB |
Output is correct |
24 |
Correct |
417 ms |
39508 KB |
Output is correct |
25 |
Correct |
173 ms |
38524 KB |
Output is correct |
26 |
Correct |
348 ms |
38532 KB |
Output is correct |
27 |
Correct |
344 ms |
41112 KB |
Output is correct |
28 |
Correct |
274 ms |
39008 KB |
Output is correct |
29 |
Correct |
338 ms |
40312 KB |
Output is correct |
30 |
Correct |
222 ms |
38524 KB |
Output is correct |
31 |
Correct |
235 ms |
40596 KB |
Output is correct |
32 |
Correct |
211 ms |
40444 KB |
Output is correct |
33 |
Correct |
394 ms |
38624 KB |
Output is correct |
34 |
Correct |
227 ms |
39840 KB |
Output is correct |