이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define endl '\n'
#define int ll
using namespace std;
struct node
{
int c, f, v;
};
const int INF = 1e9;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N;
vector<node> vals;
int MX_C = 0;
for (int i = 0; i < N; i++)
{
int c, f, v;
cin >> c >> f >> v;
vals.push_back({c, f, -v});
MX_C += c;
}
cin >> M;
for (int i = 0; i < M; i++)
{
int c, f, v;
cin >> c >> f >> v;
vals.push_back({-c, f, v});
}
sort(vals.begin(), vals.end(), [&](node &a, node &b)
{ if(a.f == b.f) return a.c > b.c; return a.f > b.f; });
MX_C++;
int dp[2][MX_C];
fill_n(&dp[0][0], 2 * MX_C, -INF);
dp[0][0] = 0;
int mx = 0, prev = 0, cur = 1;
for (int i = 0; i < vals.size(); i++)
{
for (int c = MX_C - 1; c >= 0; c--)
{
dp[cur][c] = dp[prev][c];
int cores = c - vals[i].c;
if (0 <= cores && cores < MX_C)
{
dp[cur][c] = max(dp[prev][cores] + vals[i].v, dp[cur][c]);
mx = max(mx, dp[cur][c]);
}
}
swap(cur, prev);
}
cout << mx << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:53:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < vals.size(); i++)
| ~~^~~~~~~~~~~~~
# | 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... |