# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
977306 | PieArmy | Cloud Computing (CEOI18_clo) | C++17 | 103 ms | 2140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}
int n,m;
void code(){
cin>>n;
int c[n],f[n],v[n],C[n],F[n],V[n];
for(int i=0;i<n;i++){
cin>>c[i]>>f[i]>>v[i];
}
cin>>m;
for(int i=0;i<m;i++){
cin>>C[i]>>F[i]>>V[i];
}
int p[n],P[m];
iota(p,p+n,0);iota(P,P+m,0);
sort(p,p+n,[&](const int &x,const int &y){return f[x]>f[y];});
sort(P,P+m,[&](const int &x,const int &y){return F[x]>F[y];});
ll dp[n+1][51];
for(int i=0;i<=n;i++){
for(int j=0;j<=50;j++){
dp[i][j]=-inf;
}
}
dp[0][0]=0;
for(int i=0;i<m;i++){
ll dp2[n+1][51];
for(int j=0;j<=n;j++){
for(int l=0;l<=50;l++){
dp2[j][l]=dp[j][l];
}
}
for(int j=0;j<n;j++){
for(int l=0;l<=50;l++){
if(dp[j][l]==-inf)continue;
dp[j+1][l]=max(dp[j+1][l],dp[j][l]);
if(l>=C[P[i]]){
dp2[j][l-C[P[i]]]=max(dp2[j][l-C[P[i]]],dp[j][l]+V[P[i]]);
}
if(f[p[j]]>=F[P[i]]){
if(l+c[p[j]]<C[P[i]]){
dp[j+1][l+c[p[j]]]=max(dp[j+1][l+c[p[j]]],dp[j][l]-v[p[j]]);
}
else if(l<C[P[i]]){
dp2[j+1][l+c[p[j]]-C[P[i]]]=max(dp2[j+1][l+c[p[j]]-C[P[i]]],dp[j][l]+V[P[i]]-v[p[j]]);
}
}
}
}
for(int j=0;j<=n;j++){
for(int l=0;l<=50;l++){
dp[j][l]=dp2[j][l];
}
}
}
ll ans=0;
for(int i=0;i<=n;i++){
for(int j=0;j<=50;j++){
ans=max(ans,dp[i][j]);
}
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int t=1;
if(!t)cin>>t;
while(t--){code();cout<<endl;}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |