Submission #807126

#TimeUsernameProblemLanguageResultExecution timeMemory
807126caganyanmazSnowball (JOI21_ho_t2)C++17
100 / 100
194 ms15276 KiB
#include <bits/stdc++.h> #define int int64_t using namespace std; constexpr static int MXSIZE = 2e5; constexpr static int MXLOG = 30; int mnpr[MXSIZE+1], mxpr[MXSIZE+1], n, q, v[MXSIZE], d[MXSIZE], res[MXSIZE]; int32_t main() { cin >> n >> q; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < q; i++) cin >> d[i]; for (int i = 1; i < q; i++) d[i] += d[i-1]; for (int i = 1; i <= q; i++) mnpr[i] = mxpr[i] = d[i-1]; for (int i = 1; i <= q; i++) { mnpr[i] = min(mnpr[i], mnpr[i-1]); mxpr[i] = max(mxpr[i], mxpr[i-1]); } #ifdef DEBUGGING for (int i = 0; i <= q; i++) cout << mnpr[i] << " "; cout << "\n"; for (int i = 0; i <= q; i++) cout << mxpr[i] << " "; cout <<"\n"; #endif res[0] = -mnpr[q]; for (int i = 1; i < n; i++) { int diff = v[i] - v[i-1]; int l = -1, r = q+1; while (r - l > 1) { int m = l+r>>1; if (mxpr[m] - mnpr[m] > diff) r = m; else l = m; } if (r == q+1) { res[i-1] += mxpr[l]; res[i] += -mnpr[l]; } else { res[i-1] += min(mxpr[r], diff + mnpr[l]); res[i] += min(-mnpr[r], diff - mxpr[l]); } } res[n-1] += mxpr[q]; for (int i = 0; i < n; i++) cout << res[i] << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:41:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |                         int m = l+r>>1;
      |                                 ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...