# Codeforces 854 - C Planning

SUM=i=1nCi(Tii)

SUM=i=1nCiTii=1nCii

Ci(Tii)+Cj(Tjj)

Ci(Tji)+Cj(Tij)

Ci(Tii)+Cj(Tjj)<Ci(Tji)+Cj(Tij)

Ci<Cj

#include <bits/stdc++.h>

using namespace std;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

struct node
{
ll p, c;
node(ll a = 0, ll b = 0)
{
p = a;
c = b;
}
};

struct cmp
{
bool operator()(node x, node y)
{
if (x.c != y.c)return x.c > y.c;
return x.p < y.p;
}
};

set<node, cmp>s;
int a[300000 + 50];
int main()
{
ll k;
int n;
scanf("%d%I64d", &n, &k);
ll ans = 0;
for (int i = 1; i <= n; i++)
{
ll c;
scanf("%I64d", &c);
s.insert(node(i, c));
if (i >= k + 1)
{
a[s.begin()->p] = i;
ans += s.begin()->c*(i - s.begin()->p);
s.erase(s.begin());
}
}
for (int i = 1; i <= k; i++)
{
a[s.begin()->p] = i + n;
ans += s.begin()->c*(i + n - s.begin()->p);
s.erase(s.begin());
}
printf("%I64d\n", ans);
//printf("%I64d\n", ans);
for (int i = 1; i <= n; i++)
{
if (i != 1)printf(" ");
printf("%d", a[i]);
}
printf("\n");
//sp;
}

09-07 1400

09-07 746

11-12 16

09-06 338

09-16 180

07-18 2948

09-06 832

09-07 225

09-07 646

09-07 211

#### Planning CodeForces - 854C

©️2020 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。