POJ 3666
此题更合适的解法应该使用左偏树,或者很神奇的DP加脑洞,不过在理解DP脑洞时候发现了更惊艳的做法思路见C题
留个坑,之后补左偏树做法吧
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int n, ans= 0;
scanf("%d", &n);
priority_queue<int> Q;
Q.push(0);
while (n--){
int t;
scanf("%d", &t);
Q.push(t);
if (Q.top()>t){
ans+= Q.top()-t;
Q.pop();
Q.push(t);
}
}
printf("%d", ans);
return 0;
}