Submission #580927

#TimeUsernameProblemLanguageResultExecution timeMemory
580927Theo830Snowball (JOI21_ho_t2)C++17
100 / 100
105 ms13892 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ll,ii> #define ull unsigned ll #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training int main(void){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,q; cin>>n>>q; vll arr; arr.pb(-INF); vector<ii>exo; f(i,0,n){ ll a; cin>>a; arr.pb(a); } arr.pb(INF); f(i,0,n+1){ exo.pb(ii(arr[i+1] - arr[i],i)); } ll ans[n+1] = {0}; ll cur = 0; ll mini = 0,maxi = 0; sort(all(exo)); reverse(all(exo)); while(q--){ ll w; cin>>w; cur += w; maxi = max(maxi,cur); mini = min(mini,cur); while(!exo.empty() && exo.back().F <= abs(mini) + maxi){ ll c = abs(mini) + maxi - exo.back().F; ll i = exo.back().S; if(maxi == cur){ ans[i] += maxi - c; ans[i+1] += abs(mini); } else{ ans[i] += maxi; ans[i+1] += abs(mini) - c; } exo.pop_back(); } } while(!exo.empty()){ ll i = exo.back().S; exo.pop_back(); ans[i] += maxi; ans[i+1] += abs(mini); } f(i,1,n+1){ cout<<ans[i]<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...