Submission #913929

#TimeUsernameProblemLanguageResultExecution timeMemory
913929goodspeed0208Snowball (JOI21_ho_t2)C++14
100 / 100
92 ms16980 KiB
#include<iostream> #include<vector> #include<algorithm> #include<utility> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int>v(n), w(q+5, 0), left(q+5, 0), right(q+5, 0); vector<int>ansleft(n), ansright(n); for (auto &i : v) cin >> i; for (int i = 1 ; i <= q ; i++) { cin >> w[i]; w[i] = w[i-1] + w[i]; right[i] = max(right[i-1], w[i]); left[i] = max(left[i-1], -w[i]); // cout << left[i] << " " << right[i] << "\n"; } ansleft[0] = left[q]; ansright[n-1] = right[q]; for (int i = 0 ; i < n-1 ; i++) { int l = 0, r = q+1, mid; while (l + 1 < r) { mid = (l + r) / 2; if (left[mid] + right[mid] <= v[i+1] - v[i]) { ansright[i] = right[mid]; ansleft[i+1] = left[mid]; l = mid; } else { r = mid; } } if (l == q) continue; if (left[r] != left[r-1]) ansleft[i+1] = v[i+1] - v[i] - ansright[i]; else ansright[i] = v[i+1] - v[i] - ansleft[i+1]; } for (int i = 0 ; i < n ; i++) { cout << ansleft[i] + ansright[i] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...