# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
713550 | NNerver | Cloud Computing (CEOI18_clo) | C++14 | 381 ms | 1252 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.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
long long dp[MAXN];
bool mark[MAXN];
int N,M;
vector<pair<int,pair<int,int> > > vec;
void update(int id,long long x){
if(!mark[id]){
mark[id]=1;
dp[id]=x;
return;
}
dp[id]=max(dp[id],x);
}
int main(){
// freopen("guard.in", "r", stdin);
// freopen("guard.out", "w", stdout);
scanf("%d",&N);
for(int i=1;i<=N;i++){
int c,f,v; scanf("%d%d%d",&c,&f,&v);
vec.push_back({-f,{c,-v}});
}
scanf("%d",&M);
for(int i=1;i<=M;i++){
int c,f,v; scanf("%d%d%d",&c,&f,&v);
vec.push_back({-f,{c,v}});
}
sort(vec.begin(),vec.end());
memset(mark,0,sizeof(mark));
mark[0]=1;
dp[0]=0;
for(int i=1;i<=N+M;i++){
int f=-vec[i-1].first;
int c=vec[i-1].second.first;
int v=vec[i-1].second.second;
if(v>0){
for(int j=0;j+c<=N*50;j++){
if(mark[j+c]) update(j,dp[j+c]+v);
}
}
else{
for(int j=N*50;j>=c;j--){
if(mark[j-c]) update(j,dp[j-c]+v);
}
}
}
long long ans=0;
for(int i=1;i<=N*50;i++)if(mark[i]) ans=max(ans,dp[i]);
printf("%lld\n",ans);
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... |