Codeforces Round #134 (Div. 2)B. Airport

由于人数不多,可以利用优先队列。每次(每个人)选择座位最多或最少的飞机。

时间复杂度:O(n*logm)

由于当时某个地方少输入了一个分号,导致编译器提出各种error,导致我很长时间以为是自己的优先队列写错了,耽误了很久,导致第二题拿的分数很少,也影响了第三题的分数。不然很有可能那个高一点的名次的,太久没做题了,好搓一个。。。

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;

const int N = 1005;

struct cmp
{
	bool operator ()(int a, int b)
	{
		return a > b;
	}
};

int main()
{
	int n,m;
	int p;
	int ans;
	priority_queue<int> qMax;
	priority_queue<int,vector<int>,cmp> qMin;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>p;
		qMin.push(p);
		qMax.push(p);
	}
	//cal max
	int t = n;
	ans = 0;
	while(t)
	{
		int x = qMax.top();
		ans += x;
		qMax.pop();
		if(x-1>0)qMax.push(x-1);
		t--;
	}
	cout<<ans<<' ';

	//cal min
	t = n;
	ans = 0;
	while(t)
	{
		int x = qMin.top();
		ans += x;
		qMin.pop();
		if(x-1>0)qMin.push(x-1);
		t--;
	}
	cout<<ans<<endl;	
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值