本题的正解应该是离散化+DP两次,然而数据过水以至于下面的代码都能通过
int main() {
read(n);
for (int i = 1;i <= n;++i) read(p[i]),b[i] = p[i];
std::sort(b+1,b+1+n);
for (int i = 1;i <= n;++i) {
int tmp = INF;
for (int j = 1;j <= n;++j) {
tmp = min(f[i-1][j],tmp);
f[i][j] = tmp + abs(p[i] - b[j]);
}
}
int ans = INF;
for (int i = 1;i <= n;++i) {
ans = min(ans,f[n][i]);
}
printf("%d",ans);
}
故请求加强数据