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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 2001;
const ll VMAX = 100001;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 30013;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;
ll n, m;
ll dp[2][VMAX];
struct ura{
ll f, c, v;
}v[NMAX * 2];
bool cmp(ura a, ura b){
if(a.f != b.f)
return a.f > b.f;
return a.v < b.v;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll i, j;
cin >> n;
for(i = 1; i <= n; i++){
cin >> v[i].c >> v[i].f >> v[i].v;
v[i].v = -v[i].v;
}
cin >> m;
for(i = 1; i <= m; i++){
cin >> v[n + i].c >> v[n + i].f >> v[n + i].v;
}
n += m;
sort(v + 1, v + n + 1, cmp);
for(i = 0; i <= n; i++){
for(j = 0; j < VMAX; j++){
dp[i][j] = -HALF;
}
}
dp[0][0] = 0;
for(i = 1; i <= n; i++){
int act = i % 2;
int last = (i - 1) % 2;
for(ll cores = 0; cores < VMAX; cores++){
dp[act][cores] = dp[last][cores];
}
if(v[i].v < 0){
ll val = -v[i].v;
for(ll cores = 0; cores < VMAX - v[i].c; cores++){
dp[act][cores + v[i].c] = max(dp[act][cores + v[i].c], dp[last][cores] - val);
}
}else{
for(ll cores = v[i].c; cores < VMAX; cores++){
dp[act][cores - v[i].c] = max(dp[act][cores - v[i].c], dp[last][cores] + v[i].v);
}
}
}
ll maxim = 0;
for(i = 0; i < VMAX; i++){
maxim = max(maxim, dp[n % 2][i]);
}
cout << maxim;
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... |