codefroce 854 A.Fraction

题解:贪心,每次从能够出发的飞机中取一个最大的就好啦,用一个队列维护一下~

ac代码:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
struct node
{
    ll v;
    int id;
    friend bool operator <(node a,node b)
    {
        return a.v < b.v;
    }
}a[300010];

int tt[300010];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%I64d",&a[i].v);
        a[i].id=i;
    }
    ll ans=0;
   // cout<<"12"<<endl;
    priority_queue<node> que;
    int time=m;
    for(int i=1;i<=m;i++) que.push(a[i]);
   // cout<<"123"<<endl;
    while(!que.empty())
    {
        ++time;
        if(time <= n)que.push(a[time]);
        node now=que.top();
        que.pop();
        int id=now.id;
        tt[id]=time;// now time
        ans+=(time-id)*a[id].v;
    }
    //cout<<"1234"<<endl;
    printf("%I64d\n",ans);
    printf("%d",tt[1]);
    for(int i=2;i<=n;i++) printf(" %d",tt[i]);
    cout<<endl;
    return 0;
}

 

posted @ 2017-09-07 19:08  猪突猛进!!!  阅读(119)  评论(0编辑  收藏  举报