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 LL long long
#define pb push_back
#define NINF -1000000000000000LL;
/* Date: 9/5/21
* Link: https://oj.uz/problem/view/CEOI18_clo
* Verdict:
*/
struct Option {
int c, f, v;
Option(int _c, int _f, int _v) {
c = _c; f = _f; v = _v;
}
inline bool operator<(const Option& o) {
if (f != o.f) {
return f > o.f;
}
return v < o.v;
}
};
vector<Option> options;
LL dp[2][100005];
int N, M;
int main() {
ios::sync_with_stdio(0);
#pragma omp parallel for
for (int i = 0; i < 100005; i++) {
dp[0][i] = NINF;
dp[1][i] = NINF;
}
cin >> N;
for (int i = 0; i < N; i++) {
int c, f, v;
cin >> c >> f >> v;
options.push_back(Option(c, f, -v));
}
cin >> M;
for (int i = 0; i < M; i++) {
int c, f, v;
cin >> c >> f >> v;
options.push_back(Option(-c, f, v));
}
sort(options.begin(), options.end());
int crow = 0;
int rrow = 1;
const int len = N+M;
dp[0][0] = 0;
for (int i = 0; i < len; i++) {
const int cc = options[i].c;
const int cv = options[i].v;
const int lim = min(100000, 100000+cc);
const int start = max(0, cc);
#pragma omp parallel for
for (int j = start; j <= lim; j++) {
dp[rrow][j] = max(dp[crow][j], dp[crow][j-cc]+cv);
}
for (int j = 0; j < start; j++) {
dp[rrow][j] = dp[crow][j];
}
for (int j = lim+1; j <= 100000; j++) {
dp[rrow][j] = dp[crow][j];
}
crow = rrow;
rrow = 1 ^ rrow;
}
LL ans = 0;
for (int i = 0; i < len; i++) {
ans = max(ans, dp[crow][i]);
}
cout << ans << endl;
}
Compilation message (stderr)
clo.cpp:29: warning: ignoring '#pragma omp parallel' [-Wunknown-pragmas]
29 | #pragma omp parallel for
|
clo.cpp:56: warning: ignoring '#pragma omp parallel' [-Wunknown-pragmas]
56 | #pragma omp parallel for
|
# | 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... |