This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MAXN = 200000;
ll levo[MAXN+5];
ll desno[MAXN+5];
ll x[MAXN+5];
ll pre[MAXN+5], minpref[MAXN+5], maxpref[MAXN+5];
const ll INF = 2000000000000000000LL;
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> x[i];
}
for(int i=1; i<=m; i++){
cin >> pre[i];
pre[i] += pre[i-1];
maxpref[i] = max(maxpref[i-1], pre[i]);
minpref[i] = min(minpref[i-1], pre[i]);
}
for(int i=1; i<=n; i++) levo[i] = desno[i] = x[i];
x[0] = -INF;
x[n+1] = INF;
desno[0] = -INF;
for(int i=1; i<=n; i++){
ll l = x[i]+1, r = min(x[i+1], maxpref[m] + x[i]), res = x[i];
while(l <= r){
ll mid = (l+r)/2;
int ind1 = lower_bound(maxpref+1, maxpref+1+m, mid - x[i]) - maxpref;
ll x2 = minpref[ind1];
if(x[i+1] + x2 >= mid){
l = mid+1;
res = mid;
}
else r = mid-1;
}
desno[i] = res;
}
for(int i=1; i<=n; i++){
levo[i] = max(x[i] + minpref[m], desno[i-1]);
cout << desno[i] - levo[i] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |