이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXS = 1e5;
const int INF = 0x3f3f3f3f3f3f3f3f;
struct O {
int c, f, v;
bool t;
O(int a = 0, int b = 0, int x = 0, bool d = 0) : c(a), f(b), v(x), t(d) {}
bool operator < (const O& a) {
return (make_pair(f, t) < make_pair(a.f, a.t));
}
};
int ant[MAXS + 10], at[MAXS + 10];
int32_t main() {
int n, m;
vector<O> orders;
cin >> n;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
orders.push_back(O(c, f, v, 1));
}
cin >> m;
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
orders.push_back(O(c, f, v, 0));
}
sort(orders.begin(), orders.end());
//for (int i = 0; i <= MAXS; i++) ant[i] = -INF;
//ant[0] = 0;
int ans = 0;
for (int i = 0; i < (n + m); i++) {
auto u = orders[i];
//cout << u.c << " " << u.f << " " << u.v << " " << u.t << "\n";
for (int j = 0; j <= MAXS; j++) {
at[j] = ant[j];
if (u.t) {
// comprar pc
if ((j + u.c) <= MAXS) {
at[j] = max(at[j], ant[j + u.c] - u.v);
}
} else {
if ((j - u.c) >= 0LL) {
at[j] = max(at[j], ant[j - u.c] + u.v);
}
}
//if (at[j] > ans) cout << i << " " << j << "\n";
//ans = max(ans, at[j]);
}
swap(at, ant);
}
cout << ant[0] << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int32_t main()':
clo.cpp:39:9: warning: unused variable 'ans' [-Wunused-variable]
39 | int ans = 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... |