This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Autor: Bartłomiej Czarkowski
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
const int N = 201000;
int n, q;
long long odp[N];
long long t[N];
long long w[N];
long long pw[N];
long long pref_min[N];
long long pref_max[N];
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &t[i]);
}
for (int i = 1; i <= q; ++i) {
scanf("%lld", &w[i]);
pw[i] = pw[i - 1] + w[i];
pref_min[i] = min(pref_min[i - 1], pw[i]);
pref_max[i] = max(pref_max[i - 1], pw[i]);
}
odp[1] -= pref_min[q];
odp[n] += pref_max[q];
for (int i = 1; i < n; ++i) {
long long dif = t[i + 1] - t[i];
int bp = 0, bk = q + 1, bs;
while (bk - bp > 1) {
bs = (bp + bk) / 2;
if (pref_max[bs] - pref_min[bs] < dif) {
bp = bs;
}
else {
bk = bs;
}
}
debug(t[i], t[i + 1], bk, pref_min[bk], pref_max[bk]);
if (bk == q + 1) {
odp[i] += pref_max[q];
odp[i + 1] -= pref_min[q];
}
else if (w[bk] < 0) {
odp[i] += pref_max[bk];
odp[i + 1] += dif - pref_max[bk];
}
else {
debug("c", -pref_min[bk], dif + pref_min[bk]);
odp[i + 1] -= pref_min[bk];
odp[i] += dif + pref_min[bk];
}
}
for (int i = 1; i <= n; ++i) {
printf("%lld\n", odp[i]);
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%lld", &t[i]);
| ~~~~~^~~~~~~~~~~~~~~
Main.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%lld", &w[i]);
| ~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |