标签:amp type turn can clu ase include planning lis
题意:给出每个航班花费和顺序,求新顺序使得花费最少
思路:肯定是花费最大的先决定,二分一下
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
标签:amp type turn can clu ase include planning lis
原文地址:http://www.cnblogs.com/hhxj/p/7491086.html