This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*raghav0307 - Raghav Gupta*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
#define int ll
struct Item{
int c, f, v, prod;
Item (int c_, int f_, int v_, int prod_) :
c(c_), f(f_), v(v_), prod(prod_) {}
};
bool custom(Item a, Item b){
if(a.f < b.f)
return false;
if(a.f > b.f)
return true;
return a.prod < b.prod;
}
const int inf = 1e15;
vector<Item> v;
vector<int> dp;
signed main(){
fast_io();
int n; cin >> n;
int tCores = 0;
for(int i = 0; i < n; i++){
int c, f, vv;
cin >> c >> f >> vv;
v.push_back(Item(c, f, vv, 1));
tCores += c;
}
int m; cin >> m;
for(int i = 0; i < m; i++){
int c, f, vv;
cin >> c >> f >> vv;
v.push_back(Item(c, f, vv, 2));
}
sort(v.begin(), v.end(), custom);
dp.resize(tCores + 1, -inf);
dp[0] = 0ll;
for(auto &x : v){
if(x.prod == 1){
for(int i = tCores - x.c; i >= 0; i--){
dp[i + x.c] = max(dp[i + x.c], dp[i] - x.v);
}
}
else if(x.prod == 2){
for(int i = x.c; i <= tCores; i++){
dp[i - x.c] = max(dp[i-x.c], dp[i] + x.v);
}
}
}
int ans = 0;
for(auto x : dp)
ans = max(ans, x);
cout << ans;
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... |