Codeforces Round #433 (Div. 2 C. Planning(优先队列)
来源:互联网 发布:vb中index 编辑:程序博客网 时间:2024/05/29 09:22
传送门
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are nflights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.
Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first kminutes of the day, so now the new departure schedule must be created.
All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so — their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule.
Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport.
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 300 000), here n is the number of flights, and kis the number of minutes in the beginning of the day that the flights did not depart.
The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 107), here ci is the cost of delaying the i-th flight for one minute.
The first line must contain the minimum possible total cost of delaying the flights.
The second line must contain n different integers t1, t2, ..., tn (k + 1 ≤ ti ≤ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them.
5 24 2 1 10 2
203 6 7 4 5
Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)·4 + (4 - 2)·2 + (5 - 3)·1 + (6 - 4)·10 + (7 - 5)·2 = 38burles.
However, the better schedule is shown in the sample answer, its cost is (3 - 1)·4 + (6 - 2)·2 + (7 - 3)·1 + (4 - 4)·10 + (5 - 5)·2 = 20 burles.
题意:
用一个优先队列贪心一下。
//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define s_1(x) scanf("%d",&x)#define s_2(x,y) scanf("%d%d",&x,&y)#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define fOR(n,x,i) for(int i=n;i>=x;i--)#define fOr(n,x,i) for(int i=n;i>x;i--)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db double#define ll long long#define mp make_pair#define pb push_backtypedef pair<long long int,long long int> ii;typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=1e3+10;const int maxx=600005;const double EPS=1e-8;const double eps=1e-8;const int mod=1e9+7;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;int n,k;int ar[maxx],a[maxx];priority_queue<ii> p;int main(){s_2(n,k); FOR(1,n,i) scan_d(a[i]);for(int i=1;i<=k;i++) p.push(ii(a[i],i)); LL ans=0;for(int i=k+1;i<=n+k;i++) { p.push(ii(a[i],i)); ii q=p.top(); //cout<<q.first<<" "<<q.second<<endl; p.pop(); ans+=(i-q.second)*q.first; ar[q.second]=i; } print(ans); FOR(1,n,i) { if(i==1) printf("%d",ar[i]); else printf(" %d",ar[i]); } return 0;}
- Codeforces Round #433 (Div. 2 C. Planning(优先队列)
- Codeforces Round #433 (Div. 2) C. Planning
- Codeforces Round #433 (Div. 2) C. Planning
- Codeforces Round #433 (Div. 2) C. Planning(贪心)
- Codeforces Round #433 (2)C:Planning
- Codeforces Round #433 (Div. 2)-贪心-C. Planning
- Codeforces Round #357 (Div. 2)-C. Heap Operations(优先队列)
- Codeforces Round #433 (Div. 2, C. Planning (贪心+简单实现)
- Codeforces Round #433Div. 2 D Jury Meeting 优先队列
- Codeforces Round #303 (Div. 2)-D. Queue(优先队列)
- Codeforces Round #350 (Div. 2)(D)优先队列
- Codeforces Round #357 (Div. 2) C. Heap Operations (优先队列)
- Codeforces Round #357 (Div. 2) -- C. Heap Operations (优先队列模拟)
- Codeforces Round #357 (Div. 2) C. Heap Operations(优先队列)
- Codeforces Round #357 (Div. 2) C. Heap Operations(模拟,优先队列)
- Codeforces Round #390 (Div. 2)(A,B,C(记忆化搜索),D(贪心,优先队列))
- Codeforces 854 C Planning(优先队列+贪心)
- [codeforces] 854C. Planning(优先队列)
- linux 查看是否安装了MySQL
- 采用ISegment进行点转线(或点转面)时容易出现的错误
- 穷举n位二进制
- ccf 201612-4 压缩编码 石子合并问题(DP+平行四边形优化)
- Mysql数据类型---字符串类型
- Codeforces Round #433 (Div. 2 C. Planning(优先队列)
- python类与对象part1
- Python pickle模块学习(超级详细)
- Lintcode116 Jump Game solution 题解
- Mysql数据类型---SET
- SpringData详解
- 八皇后问题
- Mysql数据类型---ENUM
- ARCore:从哪里冒出来的ARCore