# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1268294 | sun2305 | Cloud Computing (CEOI18_clo) | C++20 | 631 ms | 2120 KiB |
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll,ll>
#define maxn 2005
#define task "DATPHONG"
using namespace std;
ll n,m,sum,ans;
const ll inf=1e18;
struct dt{ll c,f,v;};
vector<dt> st;
bool cmp(dt a, dt b){
if(a.f==b.f) return a.v<b.v;
return a.f>b.f;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin>>n;
for(ll i=1; i<=n; i++){
ll c,f,v; cin>>c>>f>>v;
sum+=c; st.push_back({c,f,-v});
}
cin>>m;
for(ll i=1; i<=m; i++){
ll c,f,v; cin>>c>>f>>v;
st.push_back({-c,f,v});
}
sort(st.begin(), st.end(), cmp);
vector<ll> f(sum+5, -inf);
f[0]=0;
for(dt x:st){
vector<ll> g(f);
for(ll j=0; j<=sum; j++){
if(x.c<=j and j-x.c<=sum and f[j-x.c]!=-inf)
g[j]=max(g[j], f[j-x.c]+x.v);
}
f=g;
}
for(ll i=0; i<=sum; i++) ans=max(ans, f[i]);
cout<<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... |