Submission #1016260

#TimeUsernameProblemLanguageResultExecution timeMemory
1016260ZeroCoolSnowball (JOI21_ho_t2)C++14
0 / 100
1 ms388 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array #define int long long const int N = 5e5 + 20; const int INF = 1e17; const int MOD = 8; const int X = 4000; const int LOG = 21; //#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") //#pragma GCC optimize("O3") signed main(){ios_base::sync_with_stdio(false);cin.tie(0); int n, q; cin>>n>>q; int A[n]; for(int i = 0;i < n;i++)cin>>A[i]; int mn[q], mx[q]; int sum = 0; for(int i = 0;i < q;i++){ int x; cin>>x; sum += x; mn[i] = min((i ? mn[i-1] : 0), sum); mx[i] = max((i ? mx[i-1] : 0), sum); } int ans[n]; memset(ans, 0,sizeof ans); ans[0] = abs(mn[q-1]); ans[n-1] = mx[q-1]; for(int i = 1;i < n;i++){ int lo = 0; int res = 0; int hi = q-1; while(lo <= hi){ int mid = (lo + hi) / 2; if(A[i] - A[i-1] > mx[mid] - mn[mid]){ res = mid; lo = mid + 1; }else hi = mid - 1; } ans[i-1 ] += mx[res]; if(res + 1 < q && mx[res + 1] > mx[res]){ ans[i-1] += A[i] - A[i-1] - (mx[res] - mn[res]); } else if(res + 1 < q){ ans[i] += A[i] - A[i-1] - (mx[res] - mn[res]); } ans[i] += abs(mn[res]); } for(int i = 0;i < n;i++)cout<<ans[i]<<" "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...