记录编号 214286 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOI 2015]荷马史诗 最终得分 100
用户昵称 Gravatar铁策 是否通过 通过
代码语言 C++ 运行时间 0.505 s
提交时间 2015-12-15 13:20:37 内存使用 0.28 MiB
显示代码纯文本
//Noi2015 epic
#include <iostream>
#include <queue>
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
long long readint()
{
	long long ans=0;
	char c;
	while (!isdigit(c=getchar()));
	do
	{
		ans=ans*10+c-'0';
		c=getchar();	
	} while (isdigit(c));
	return ans;
}
struct Node
{
	long long w,h;
	Node(long long w,long long h):w(w),h(h){}
};
bool operator <(Node a,Node b)
{
	if (a.w<b.w)
		return false;
	if (a.w>b.w)
		return true;
	return (a.h>b.h);
}
priority_queue<Node> ans;
int main()
{
	freopen("epic.in","r",stdin);
	freopen("epic.out","w",stdout);
	long long n=readint();
	long long k=readint();
	for (long long i=0;i<n;i++)
		ans.push(Node(readint(),0));
	if ((n-1)%(k-1))
		for (long long i=0;i<(k-1)-(n-1)%(k-1);i++)
			ans.push(Node(0,0));
	long long sum=0,hm=0;
	while (ans.size()>1)
	{
		long long hi=0,s=0;
		for (long long i=0;i<k;i++)
		{
			Node ls=ans.top();
			s+=ls.w;
			hi=max(hi,ls.h);
			ans.pop();
		}
		ans.push(Node(s,hi+1));
		sum+=s;
		hm=max(hm,hi+1);
	}
	cout<<sum<<endl;
	cout<<hm<<endl;
	return 0;
}