E - Contest Score Gym - 101291E (优先队列)

Download

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int a,k;
int n[310];
long long int t=0,ans=0;

priority_queue<int,vector<int>,greater<int>>q;

int main()
{
    t=0;
    ans=0;
    cin >> a >> k;
    for(int i=1; i<=a; i++)
    {
        cin >> n[i];
    }
    for(int i=1; i<=k; i++)
    {
        q.push(n[i]);
    }
    int g=k+1;
    while(!q.empty())
    {
        t=t+q.top();
        q.pop();
        ans=ans+t;
        if(g<=a)
        {
            q.push(n[g++]);
        }
    }
    cout << ans;
    return 0;
}

 

上一篇:K - Six Sides Gym - 101291K (概率题)


下一篇:G - Gravity Gym - 101291G (字符的换位)