#include "bits/stdc++.h"
using namespace std;
#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ep emplace_back
#define pb push_back
#define pf push_front
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
const ll oo = 1e18;
int n, q;
ll x[N], d[N], ans[N];
set<pll> sad;
inline void solve() {
for (int i = 2; i <= n; ++i) {
ll dist = x[i] - x[i - 1];
sad.insert(make_pair(dist, i));
}
sad.insert(make_pair(oo, 1));
sad.insert(make_pair(oo, n + 1));
ll maxleft = 0, maxright = 0, cur = 0;
while(q--) {
ll w; cin >> w;
cur += w;
if (cur > 0) {
auto it = sad.upper_bound(make_pair(cur + maxleft, oo));
if (it != sad.begin()) {
it = prev(it);
while (true) {
auto[interval, id] = *it;
it = sad.erase(it);
ans[id] += min(maxleft, interval);
ans[id - 1] += max(interval - maxleft, 0ll);
if (it == sad.begin()) break;
it = prev(it);
}
}
maxright = max(maxright, cur);
}
if (cur < 0) {
auto it = sad.upper_bound(make_pair(maxright - cur, oo));
if (it != sad.begin()) {
it = prev(it);
while (true) {
auto[interval, id] = *it;
it = sad.erase(it);
ans[id - 1] += min(maxright, interval);
ans[id] += max(interval - maxright, 0ll);
if (it == sad.begin()) break;
it = prev(it);
}
}
maxleft = max(maxleft, -cur);
}
//
// for (int i = 1; i <= n; ++i) cout << ans[i] << endl;
// cout << endl;
}
for (auto[interval, id] : sad) {
ans[id] += maxleft;
ans[id - 1] += maxright;
}
for (int i = 1; i <= n; ++i) cout << ans[i] << endl;
}
inline void input() {
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> x[i];
return solve();
}
int main() {
if(fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
input();
return 0;
}
//2911
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | freopen(task ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | freopen(task ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |