Submission #1125071

#TimeUsernameProblemLanguageResultExecution timeMemory
1125071irmuunSnowball (JOI21_ho_t2)C++20
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n,q; cin>>n>>q; vector<ll>x(n); vector<pair<ll,ll>>dist; for(ll i=0;i<n;i++){ cin>>x[i]; if(i>0){ dist.pb({x[i]-x[i-1],i-1}); } } sort(all(dist)); vector<ll>ans(n,0); ll mn=0,mx=0,cur=0,j=0; while(q--){ ll w; cin>>w; cur+=w; ll newmn=min(mn,cur),newmx=max(mx,cur); while(j<n-1&&newmx-newmn>=dist[j].ff){ ans[dist[j].ss]+=mx; ans[dist[j].ss+1]+=abs(mn); ll left=dist[j].ff-(mx-mn); if(newmn!=mn){ ans[dist[j].ss+1]+=left; } else{ ans[dist[j].ss]+=left; } j++; } mn=min(mn,cur); mx=max(mx,cur); } ans[0]+=abs(mn); ans[n-1]+=mx; for(ll i=0;i<n;i++){ cout<<ans[i]<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...