首页 > 其他分享 >小度养小猫

小度养小猫

时间:2022-08-28 13:44:14浏览次数:58  
标签:cnt 小猫 exam int long 小度养

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);
}

标签:cnt,小猫,exam,int,long,小度养
From: https://www.cnblogs.com/xjtfate/p/16632645.html

相关文章

  • [AcWing 165] 小猫爬山
    DFS剪枝点击查看代码#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;constintN=50+10;intn,m;intw[N];intsum[N];//每组......