This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>
#include <array>
#include <functional>
#include <stack>
#include <memory>
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
using namespace std;
#define int long long
#define app push_back
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl; }(#__VA_ARGS__, ":", __VA_ARGS__)
#define debugv(v) do { cout << #v << ": "; for (auto x : v) cout << x << ' '; cout << endl; } while(0)
#else
#define debug(...)
#define debugv(v)
#endif
int32_t main() {
cin.tie(0);ios_base::sync_with_stdio(0);
int n, q;
cin >> n >> q;
vector <int> x(n), w(q), mx(q + 1), mn(q + 1);
for (int i = 0; i < n; ++i) {
cin >> x[i];
}
int cur = 0;
for (int i = 0; i < q; ++i) {
cin >> w[i];
cur += w[i];
mx[i + 1] = max(mx[i], cur);
mn[i + 1] = min(mn[i], cur);
}
vector <int> ans(n);
ans.front() -= mn.back();
ans.back() += mx.back();
for (int i = 0; i + 1 < n; ++i) {
int d = x[i + 1] - x[i];
if (mx.back() - mn.back() < d) {
ans[i] += mx.back();
ans[i + 1] -= mn.back();
}
else {
int l = 0, r = q;
while (l < r - 1) {
int m = (l + r) / 2;
if (mx[m] - mn[m] < d) {
l = m;
}
else {
r = m;
}
}
ans[i] += mx[l];
ans[i + 1] -= mn[l];
int os = d - mx[l] + mn[l];
if (w[l] > 0) {
ans[i] += os;
}
else {
ans[i + 1] += os;
}
}
}
for (int e : ans) {
cout << e << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |