# Bzoj5441 [ceoi2018]cloud computing

## 当背包DP遇上动态的体积

Posted by yjjr's blog on September 17, 2018

# 题面

## Sample Input

4
4 2200 700
2 1800 10
20 2550 9999
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550


## Sample Output

350


# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define mem(x,num) memset(x,num,sizeof x)
#define ll long long
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define inf 0x3f3f3f
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=2e3+6;
struct node{int c,f,v;}q[maxn<<1];
inline bool cmp(node a,node b){return a.f==b.f?a.v<b.v:a.f>b.f;}
int n,m,tot;ll f[maxn*50+6],ans;
int main(){
sort(q+1,q+1+n+m,cmp);
mem(f,-inf);f[0]=0;
rep(i,1,n+m){
if(q[i].c>0){
dep(j,tot,0)f[j+q[i].c]=max(f[j+q[i].c],f[j]+q[i].v);
tot+=q[i].c;
}
else rep(j,0,q[i].c+tot)f[j]=max(f[j-q[i].c]+q[i].v,f[j]);
}
rep(i,0,tot)ans=max(ans,f[i]);
cout<<ans<<endl;
return 0;
}