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;
}
posted @ 2021-12-13 23:45  soroboruo  阅读(49)  评论(0编辑  收藏  举报