Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning

Posted 早知如此绊人心,何如当初莫相识。

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning相关的知识,希望对你有一定的参考价值。

题意:给出每个航班花费和顺序,求新顺序使得花费最少

思路:肯定是花费最大的先决定,二分一下

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+100;
 4 typedef long long ll;
 5 
 6 struct node{
 7     ll x;
 8     int id;
 9     ll yy;
10 }a[300004];
11 bool cmp(node p,node q){
12     return p.x>q.x;
13 }
14 bool cmp1(node p,node q){
15     return p.id<q.id;
16 }
17 set<int >s;
18 int main(){
19     int n,k;
20     cin>>n>>k;
21     for(int i=1;i<=n;i++){
22        scanf("%lld",&a[i].x);
23        a[i].id=i;
24        s.insert(i+k);
25     }
26     sort(a+1,a+1+n,cmp);
27     ll sum=0;
28     for(int i=1;i<=n;i++){
29         int xx=a[i].id;
30         int k=*s.lower_bound(xx);
31         a[i].yy=k;
32         sum+=(k-xx)*a[i].x;
33         s.erase(k);
34     }
35     cout<<sum<<endl;
36     sort(a+1,a+1+n,cmp1);
37     for(int i=1;i<=n;i++)
38         printf("%lld ",a[i].yy);
39 }

 

以上是关于Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #433

codeforces round #433 div2

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

codeforces比赛题解#854 CF Round #433 (Div.2)

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning