把所有硬盘按照格完了之后是容量变大还是变小分成两类,先做变大的,后做变小的,变大的按原容量升序排序,变小的按新容量降序排序
证明感性理解一下就好……
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
*/