求助!被最后一个hack卡了
查看原帖
求助!被最后一个hack卡了
570981
issaccheng楼主2025/2/8 15:11

和标成比对没有区别啊:(

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6 + 5;
struct save { ll x, p, c; }num[N];
struct s2 { ll a, b; }st[N], tt;
ll stl, str=1, dp, sum[N], tim[N];
long double slop(s2 x, s2 y) {
	if (x.a == y.a)return 1e18;
	return (long double)(y.b - x.b) / (y.a - x.a);
}
int main() {
	ll n, x, p, c, ans = 0;
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> x >> p >> c,num[i] = { x,p,c };
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + num[i].p, tim[i] = tim[i - 1] + num[i].p * num[i].x;
	st[++stl] = { 0,0 };
	for (int i = 1, mid; i <= n; i++) {
		while (stl < str && slop(st[stl], st[stl + 1]) < num[i].x)stl++;
		dp = num[i].x * sum[i] - num[i].x * st[stl].a - tim[i] + st[stl].b + num[i].c;
		if (num[i].p == 0)ans = min(ans, dp);
		else ans = dp;
		tt = { sum[i],dp + tim[i] };
		while (str > stl && slop(st[str], tt) < slop(st[str - 1], st[str]))
			str--;
		st[++str] = tt;
	}
	cout << ans;
}
2025/2/8 15:11
加载中...