| 比赛 | 
    10101115 | 
    评测结果 | 
    AWAWWWWWWW | 
    | 题目名称 | 
    矩形分割 | 
    最终得分 | 
    20 | 
    | 用户昵称 | 
    .Xmz | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2010-11-15 08:34:06 | 
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
int n,m;
int x[2001],y[2001];
int hx,hy;
int nx,ny;
int cost;
int cmp (const void *a,const void *b)
{
	return *((int *)a) - *((int *)b);
}
void gx()
{
	cost+=nx*x[n];
	hx-=x[n];
	n--;
	ny++;
}
void gy()
{
	cost+=ny*y[m];
	hy-=y[m];
	m--;
	nx++;
}
int main()
{
	freopen("cut.in","r",stdin);
	freopen("cut.out","w",stdout);
	scanf("%d%d",&n,&m);
	n--;m--;
	nx=1;ny=1;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x[i]); hx+=x[i];
	}
	for (int i=1;i<=m;i++)
	{
		scanf("%d",&y[i]); hy+=y[i];
	}
	qsort(x+1,n,sizeof(x[0]),cmp);
	qsort(y+1,m,sizeof(y[0]),cmp);
	
	while (n!=0 && m!=0)
	{
		if (nx*hx>ny*hy) gx();
		else gy();
	}
	while (n!=0) gx();
	while (m!=0) gy();
	printf("%d\n",cost);
	return 0;
}