This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// #if (code == true)
#include <bits/stdc++.h>
using namespace std;
#define pll pair<long long, long long>
#define len(a) ((int)((a).size()))
#define all(a) a.begin(), a.end()
#define add push_back
#define mkp make_pair
#define ll long long
#define fr first
#define sc second
const long long INF = 1000000000ll * 1000000003ll;
const long long MOD = 1000000007ll;
const int N = 2e5 + 5;
ll n, q;
ll x[N], w, ans[N];
pll dist[N];
void solve(){
cin >> n >> q;
for(int i = 0; i < n; i++){
cin >> x[i];
if(i > 0) dist[i] = {x[i] - x[i - 1], i};
}
sort(dist + 1, dist + n);
ll now = 0, r = 0, l = 0, ind = 1;
while(q--){
cin >> w;
now += w;
l = max(l, -now);
r = max(r, +now);
while(dist[ind].fr < l + r && ind < n){
if(w > 0){
ans[dist[ind].sc] += l;
ans[dist[ind].sc - 1] += dist[ind].fr - l;
}
else{
ans[dist[ind].sc - 1] += r;
ans[dist[ind].sc] += dist[ind].fr - r;
}
ind++;
}
}
while(ind < n){
ans[dist[ind].sc] += l;
ans[dist[ind].sc - 1] += r;
ind++;
}
ans[0] += l;
ans[n - 1] += r;
for(int i = 0; i < n; i++){
cout << ans[i] << "\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int _ = 1;
// cout << fixed;
// cout.precision(15);
// cin >> _ ;
while(_--) solve();
return 0;
}
/// #else
/// #include <bits/stdc++.h> using namespace std; int main() { cout << "Hello World!"; }
/// #endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |