# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716871 | Baytoro | Snowball (JOI21_ho_t2) | C++17 | 539 ms | 26452 KiB |
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;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=2e5+5;
void solve(){
int n,q;cin>>n>>q;
vector<int> a(n+2);
a[0]=-INF,a[n+1]=INF;
for(int i=1;i<=n;i++) cin>>a[i];
vector<int> querys(q+1),mn(q+1),mx(q+1);
set<pair<int,int>> st;
for(int i=1;i<=q;i++){
cin>>querys[i];
querys[i]+=querys[i-1];
mx[i]=max(mx[i-1],querys[i]);
mn[i]=min(mn[i-1],querys[i]);
st.insert({mx[i]-mn[i],i});
}
for(int i=1;i<=n;i++){
int A=a[i]-a[i-1];
int B=a[i+1]-a[i];
int ans=0;
auto it=st.lower_bound({A,0});
if(it==st.end()) ans-=mn[q];
else{
int j=(*it).sc;
ans+=(querys[j]>querys[j-1]? -mn[j] : A-mx[j]);
}
it=st.lower_bound({B,0});
if(it==st.end()) ans+=mx[q];
else{
int j=(*it).sc;
ans+=(querys[j]<querys[j-1]? mx[j] : B+mn[j]);
}
cout<<ans<<endl;
}
}
main(){
//fopn("team");
//ios;
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |