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>
#pragma GCC optimize("unroll-loops")
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
const ll INF = LLONG_MIN / 2;
struct Object {
int c;
ll f, v;
bool operator<(Object B) {
if (f == B.f) return v < B.v;
return f > B.f;
}
} obj[4001];
ll dp[2][100001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n;
FOR(i, 0, n) {
cin >> obj[i].c >> obj[i].f >> obj[i].v;
obj[i].v *= -1;
}
cin >> m;
FOR(i, n, n + m) {
cin >> obj[i].c >> obj[i].f >> obj[i].v;
obj[i].c *= -1;
}
sort(obj, obj + n + m);
FOR(i, 0, 2) FOR(j, 0, 100001) dp[i][j] = INF;
dp[1][0] = 0;
FOR(i, 0, n + m) {
FOR(j, 0, 99951) {
if (j >= obj[i].c)
dp[i & 1][j] = max(dp[1 - i & 1][j],
dp[1 - i & 1][j - obj[i].c] + obj[i].v);
else
dp[i & 1][j] = dp[1 - i & 1][j];
}
FOR(j, 0, 100001) dp[1 - i & 1][j] = INF;
}
cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + 100001);
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:41:41: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
dp[i & 1][j] = max(dp[1 - i & 1][j],
~~^~~
clo.cpp:42:41: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
dp[1 - i & 1][j - obj[i].c] + obj[i].v);
~~^~~
clo.cpp:44:37: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
dp[i & 1][j] = dp[1 - i & 1][j];
~~^~~
clo.cpp:46:32: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
FOR(j, 0, 100001) dp[1 - i & 1][j] = INF;
~~^~~
clo.cpp:49:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + 100001);
~~^~~~~~~~~
clo.cpp:49:52: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
cout << *max_element(dp[1 - (n + m) & 1], dp[1 - (n + m) & 1] + 100001);
~~^~~~~~~~~
# | 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... |