BZOJ4619 [Wf2016]Swap Space

把所有硬盘按照格完了之后是容量变大还是变小分成两类,先做变大的,后做变小的,变大的按原容量升序排序,变小的按新容量降序排序

证明感性理解一下就好……

UPD:证明见 BZOJ3709 [PA2014]Bohater

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<queue>
#include<stack>
using namespace std;
#define MAXN 1000010
#define MAXM 1010
#define INF 1000000000
#define MOD 1000000007
#define eps 1e-8
#define ll long long
struct db{
	int x;
	int y;
};
db a[MAXN],b[MAXN];
int n,tot1,tot2;
ll ans,rem;
bool cmp1(db x,db y){
	return x.x<y.x;
}
bool cmp2(db x,db y){
	return x.y>y.y;
}
void cal(int x,int y){
	rem-=x;
	if(rem<0){
		ans-=rem;
		rem=0;
	}
	rem+=y;
}
int main(){
	int i,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d%d",&x,&y);
		if(x<y){
			a[++tot1].x=x;
			a[tot1].y=y;
		}else{
			b[++tot2].x=x;
			b[tot2].y=y;
		}
	}
	sort(a+1,a+tot1+1,cmp1);
	sort(b+1,b+tot2+1,cmp2);
	for(i=1;i<=tot1;i++){
		cal(a[i].x,a[i].y);
	}
	for(i=1;i<=tot2;i++){
		cal(b[i].x,b[i].y);
	}
	printf("%lld\n",ans);
	return 0;
}

/*
10
11 82
98 12
78 53
15 10
41 2
81 58
53 42
30 41
25 39
20 54
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值