# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716816 | Baytoro | Cloud Computing (CEOI18_clo) | C++17 | 626 ms | 2124 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;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=2e5+5;
struct node{
int c,f,p;
} a[4005];
bool cmp(node a, node b){
if(a.f==b.f) return a.p<b.p;
return a.f>b.f;
}
void solve(){
int n;cin>>n;
int sum=0;
for(int i=0;i<n;i++) {cin>>a[i].c>>a[i].f>>a[i].p;a[i].p=-a[i].p,sum+=a[i].c;}
int m;cin>>m;
for(int i=n;i<n+m;i++) {cin>>a[i].c>>a[i].f>>a[i].p;a[i].c=-a[i].c;}
sort(a,a+n+m,cmp);
vector<int> pref(sum+1,-INF),prev(sum+1,-INF);
pref[0]=prev[0]=0;
for(int i=0;i<n+m;i++){
for(int j=0;j<=sum;j++){
int x=j-a[i].c;
if(0<=x && x<=sum && pref[x]!=-INF){
prev[j]=max(prev[j],pref[x]+a[i].p);
}
}
pref=prev;
}
int ans=-INF;
for(auto it: pref) ans=max(ans,it);
cout<<ans;
}
main(){
//fopn("team");
//ios;
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
}
}
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... |