#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<long long> pos(n);
for (int i = 0; i < n; i++) cin >> pos[i];
vector<long long> w(q);
for (int i = 0; i < q; i++) cin >> w[i];
vector<long long> weight(n, 0);
// snow[x] = true means interval [x, x+1) still has snow
map<long long, bool> snow;
for (int day = 0; day < q; day++) {
for (int i = 0; i < n; i++) {
long long from = pos[i];
long long to = pos[i] + w[day];
if (from < to) {
// moving east
for (long long x = from; x < to; x++) {
if (!snow.count(x)) snow[x] = true;
if (snow[x]) {
weight[i]++;
snow[x] = false;
}
}
} else {
// moving west
for (long long x = from - 1; x >= to; x--) {
if (!snow.count(x)) snow[x] = true;
if (snow[x]) {
weight[i]++;
snow[x] = false;
}
}
}
pos[i] = to;
}
}
for (int i = 0; i < n; i++) {
cout << weight[i] << '\n';
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |