bzoj4194 Mat
对 \(k,b\) 做前缀和,发现是对于所有 \(i\) 求 \(A_i+B\) 的最小值,求一个凸包出来就好了。
Code
int main() {
#ifdef ldxcaicai
freopen("lx.in", "r", stdin);
#endif
n = read(), m = read();
for (int i = 1; i <= n; ++i) ad[i] = readl();
for (int i = 2; i <= m; ++i) {
a[i].se = readl() + a[i - 1].se;
a[i].fi = readl() + a[i - 1].fi;
}
sort(a + 1, a + m + 1);
q[tp = 1] = 1;
for (int i = 2; i <= m; ++i) {
if (a[i].se >= a[q[tp]].se) continue;
while (tp > 1 && cal(a[i], a[q[tp - 1]]) <= cal(a[q[tp]], a[q[tp - 1]])) --tp;
q[++tp] = i;
}
int id = 1;
for (int i = 1; i <= n; ++i) {
while (id < tp && Cal(a[q[id]], i) >= Cal(a[q[id + 1]], i)) ++id;
cout << Cal(a[q[id]], i) + ad[i] << '\n';
}
return 0;
}