由于人数不多,可以利用优先队列。每次(每个人)选择座位最多或最少的飞机。
时间复杂度: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;
}