加载中...

小度养小猫

https://matiji.net/exam/contest/contestdetail/55?type=4

const int N = 1e5 + 7;
int n, k, c[N];
void solve() {
    long long ans = 0;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", &c[i]);
        ans -= (long long)i * i * c[i];
    }

    priority_queue<int> heap;
    for (int i = k + 1, cnt = 1; i <= n + k; ++ i) {
        while (cnt <= n && cnt <= i) heap.push(c[cnt ++]);
        ans += (long long)i * i * heap.top(); heap.pop();
    }
    printf("%lld\n", ans);
}
posted @ 2022-08-28 13:38  英雄不问出处c  阅读(115)  评论(0编辑  收藏  举报