이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
/> フ
| _ _|
/`ミ _x 彡
/ |
/ ヽ |
/ ̄| | | |
| ( ̄ヽ__ヽ_)_)
\二つ
**/
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define Pt Point
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define MP make_pair
#define MT make_tuple
#define typeT tuple<int, int, int>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FOD(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define MASK(i) (1 << (i))
#define BIT(k, i) (((k) >> (i)) & 1)
const int N = 2e3 + 5;
const int M = 1e5;
using namespace std;
int n, m;
ll dp[M + 5];
struct Computer {
int c, f, v;
bool operator < (const Computer &other) const {
return f > other.f;
}
} a[N];
bool Maximize(ll &a, ll b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define task "a"
//freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
cin >> n;
FOR(i, 1, n) {
int c, f, v; cin >> c >> f >> v;
a[i] = {c, f, -v};
}
cin >> m;
FOR(i, 1, m) {
int c, f, v; cin >> c >> f >> v;
a[++n] = {-c, f, v};
}
sort(a + 1, a + 1 + n);
memset(dp, -0x3f, sizeof dp);
dp[0] = 0;
FOR(i, 1, n) {
int c = a[i].c, v = a[i].v;
if (c > 0) {
FOD(j, M - c, 0) Maximize(dp[j + c], dp[j] + v);
} else FOR(j, -c, M) Maximize(dp[j + c], dp[j] + v);
}
ll res = 0;
FOR(j, 0, M) Maximize(res, dp[j]);
cout << res;
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... |