量化交易 题解

题目在主页,如有出错请指出

include <bits/stdc++.h>

using namespace std;

long long a[100005];

int main()
{
int n, cnt = 1;
while (cin >> n)
{
priority_queue < long long , vector < long long > , greater < long long > > q;
for (int i = 1;i <= n;i++)
cin >> a[i];
long long ans = 0;
for (int i = 1;i <= n;i++)
{
if (!q.empty() && a[i] > q.top())
{
ans += a[i] - q.top();
q.pop();
q.push(a[i]);
}
q.push(a[i]);
}
cout << "Case #" << cnt << ": " << ans << endl;
cnt++;
}
return 0;
}

posted @ 2025-04-26 08:15  嵇若凌  阅读(20)  评论(0)    收藏  举报