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;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
struct order{
int cores;
int fr;
int val;
int type; // type == 1 => computer, type == 2>= order
bool operator< (const order &q) const {
if(fr == q.fr){
return type > q.type;
}
return fr < q.fr;
}
};
const int M = (int)2e5+10;
const ll inf = (ll)1e18;
ll dp[M];
int main(){
fastIO;
int n;
cin >> n;
int c, f, v;
vector<order> ff;
for(int i = 0 ; i < n; i ++ ){
cin >> c >> f >> v;
ff.push_back({c,f,v,1});
}
int m;
cin >> m;
for(int i = 0; i < m ; i ++ ){
cin >> c >> f >> v;
ff.push_back({c,f,v,2});
}
sort(ff.begin(),ff.end());
for(int i = 0 ; i < M; i ++ ){
dp[i]=-inf;
}
dp[0]=0;
int mx = 0;
ll ans = 0;
for(int i = ff.size() - 1; i >= 0 ; i -- ){
if(ff[i].type == 1){
for(int j = mx; j >= 0; j -- ){
dp[j+ff[i].cores]=max(dp[j+ff[i].cores],dp[j]-ff[i].val);
}
mx += ff[i].cores;
}
else{
for(int j = ff[i].cores; j <= mx ; j ++ ){
dp[j-ff[i].cores]=max(dp[j-ff[i].cores],dp[j]+ff[i].val);
ans = max(ans,dp[j-ff[i].cores]);
}
}
}
cout << ans << "\n";
return 0;
}
# | 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... |