Submission #757838

#TimeUsernameProblemLanguageResultExecution timeMemory
757838otariusSnowball (JOI21_ho_t2)C++17
100 / 100
104 ms13416 KiB
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <cstring> #include <queue> #include <map> #include <cmath> #include <iomanip> using namespace std; #define ff first #define sc second #define pb push_back #define ll long long #define pll pair<ll, ll> #define pii pair <int, int> #define ull unsigned long long #define int long long // #define int unsigned long long const ll inf = 1e18 + 7; const ll weirdMod = 998244353; int lft[200005], rgt[200005]; void solve() { int n, k; cin >> n >> k; int arr[n + 5] = {}, wnd[k + 5] = {}; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i <= k; i++) { cin >> wnd[i]; wnd[i] += wnd[i - 1]; } vector<int> vec; for (int i = 1; i <= k; i++) { lft[i] = max(lft[i - 1], wnd[i]); rgt[i] = max(rgt[i - 1], -wnd[i]); } ll ans[n + 5] = {}; arr[0] = -inf; arr[n + 1] = inf; for (int i = 0; i <= n; i++) { if (lft[k] + rgt[k] <= arr[i + 1] - arr[i]) { ans[i] += lft[k]; ans[i + 1] += rgt[k]; continue; } int l = 1, r = k, m; while (l < r) { m = (l + r) / 2; if (lft[m] + rgt[m] > arr[i + 1] - arr[i]) r = m; else l = m + 1; } while (lft[l - 1] + rgt[l - 1] > arr[i + 1] - arr[i]) l--; if (rgt[l] != rgt[l - 1]) { ans[i] += lft[l]; ans[i + 1] += arr[i + 1] - arr[i] - lft[l]; } else {ans[i] += arr[i + 1] - arr[i] - rgt[l]; ans[i + 1] += rgt[l];} } for (int i = 1; i <= n; i++) cout << ans[i] << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...