#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false
const int MAXN = 200 * 1000 + 2;
ll x[MAXN];
ll w[MAXN];
ll spref[MAXN];
ll rekdod[MAXN];
ll rekuj[MAXN];
ll wynik[MAXN];
int main () {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i ++) {
cin >> x[i];
}
x[0] = LLONG_MIN/3LL;
x[n + 1] = LLONG_MAX/3LL;
for (int i = 1; i <= q; i ++) {
cin >> w[i];
}
for (int i = 1; i <= q; i ++) {
spref[i] = spref[i - 1] + w[i];
}
for (int i = 1; i <= q; i ++) {
rekdod[i] = max(rekdod[i - 1], spref[i]);
rekuj[i] = min(rekuj[i - 1], spref[i]);
//cout << rekdod[i] << " " << rekuj[i] << "\n";
}
for (int i = 0; i <= n; i ++) {
ll dl = x[i + 1] - x[i];
int p = 0, k = q, wyn = 0;
while (p <= k) {
int sr = (p + k)/ 2;
if ((-1LL) * rekuj[sr] + rekdod[sr] < dl) {
p = sr + 1;
wyn = sr;
} else {
k = sr - 1;
}
}
wyn ++;
wyn = min(wyn, q);
//cout << wyn << "\n";
if (spref[wyn] > spref[wyn - 1]) {
wynik[i + 1] += (-1LL) * rekuj[wyn];
wynik[i] += min(dl - (-1LL) * rekuj[wyn], rekdod[wyn]);
} else {
wynik[i] += rekdod[wyn];
wynik[i + 1] += min(dl - rekdod[wyn], (-1LL) * rekuj[wyn]);
}
}
for (int i = 1; i <= n; i ++) {
cout << wynik[i] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |