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 <iostream>
#include <vector>
#include <set>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cassert>
#include <math.h>
using namespace std;
#define endl "\n"
#define int int64_t
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FOR0(i,a) FOR(i,0,a)
#define FOR1(i,a) for (int i = (1); i <= (a); ++i)
#define TRAV(a,x) for (auto& a: x)
using pii = pair<int,int>;
using vi = vector<int>;
struct transaction{
int cores;
int frames;
int profit;
};
bool cmp(transaction a, transaction b){
if(a.frames!=b.frames){
return a.frames>b.frames;
}else{
return a.profit<b.profit;
}
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
int cores=0;
vector<transaction> transactions;
FOR0(i,N){
int a,b,c;
cin>>a>>b>>c;
cores+=a;
transactions.pb({a,b,-c});
}
int M;
cin>>M;
FOR0(i,M){
int a,b,c;
cin>>a>>b>>c;
transactions.pb({-a,b,c});
}
sort(transactions.begin(),transactions.end(),cmp);
// TRAV(i,transactions){
// cout<<i.cores<<" "<<i.frames<<" "<<i.profit<<endl;
// }
int dp[cores+3];
FOR1(i,cores){
dp[i]=-1010000000000000000;
}
dp[0]=0;
int num=1;
TRAV(i,transactions){
int cur[cores+3];
for(int c=0;c<=cores;c++){
cur[c]=dp[c];
}
int curCores=i.cores;
for(int c=0;c<=cores;c++){
int left=c-i.cores;
if(left>=0 && left<=cores && dp[left]!=(-1010000000000000000)){
cur[c]=max(cur[c],dp[left]+i.profit);
// if(dp[num][c]==4550){
// cout<<"DJIOEWJODE "<<c<<" "<<dp[num-1][left]<<" "<<left<<endl;
// }
}
}
for(int c=0;c<=cores;c++){
dp[c]=cur[c];
}
num++;
}
// FOR0(i,transactions.size()+1){
// FOR0(j,cores+1){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl<<endl<<endl;
// }
int ans=0;
FOR0(i,cores+1){
ans=max(ans,dp[i]);
}
cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int32_t main()':
clo.cpp:75:7: warning: unused variable 'curCores' [-Wunused-variable]
75 | int curCores=i.cores;
| ^~~~~~~~
# | 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... |