题解 我们枚举建厂的位置,发现有个\(n^2\)的DP.随手搞个斜率优化到\(O(n)\). #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 21000 ; const ll inf = 100000000000000LL; int n; ll f[maxn]; ll w[maxn],s[maxn],m[maxn],h[maxn],cnt[maxn]; ll d[maxn],…