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 forR(i, a) for(int i = 0; (i) < (a); ++(i))
#define REP(i, a, b) for(int i = (a); (i) < (b); ++i)
#define all(a) a.begin(), a.end()
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define printArr(arr) for(int asdfg : arr) cout << asdfg << ' '; cout << '\n'
typedef long long ll;
typedef array<int, 2> pii;
// computer: (+ cores, speed, + in profit)
struct thing{
int c, f, v;
};
const int MN = 4e3 + 10, MC=60;
const ll INF = 1e18;
thing arr[2 * MN];
signed main(){
int n; cin >> n;
forR(i, n) {
cin >> arr[i].c >> arr[i].f >> arr[i].v;
arr[i].v *= -1;
}
int m; cin >> m;
REP(i, n, n + m){
cin >> arr[i].c >> arr[i].f >> arr[i].v;
arr[i].c *= -1;
}
sort(arr, arr + n + m, [](thing& a, thing& b){return a.f > b.f || a.f == b.f && a.c > b.c;});
vector<ll> pre(MN * MC, -INF), cur(MN * MC, -INF);
pre[0] = 0; int cs=0;
forR(i, n + m){
forR(j, cs + 1) cur[j] = pre[j];
forR(j, cs + 1) if(j + arr[i].c >= 0) cur[j + arr[i].c] = max(cur[j + arr[i].c], pre[j] + arr[i].v);
cs += max(0, arr[i].c);
// forR(j, 20) cout << pre[j] << ' ';
// cout << '\n';
// forR(j, 20) cout << cur[j] << ' ';
// cout << "\n\n";
pre.swap(cur);
}
ll bes = 0;
for(ll i : pre) bes = max(bes, i);
cout << bes << '\n';
}
Compilation message (stderr)
clo.cpp: In lambda function:
clo.cpp:31:82: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
31 | sort(arr, arr + n + m, [](thing& a, thing& b){return a.f > b.f || a.f == b.f && a.c > b.c;});
| ~~~~~~~~~~~^~~~~~~~~~~~
# | 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... |