이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2004;
typedef long long ll;
const ll inf = 1e18;
struct ev
{
int c, v, f, tip;
} a[2 * Nmax];
int n, m;
void solve()
{
vector<ll> dp(50 * (n - m) + 1), old(50 * (n - m) + 1, -inf);
int i, j;
old[0] = 0;
for(i=1; i<=n; ++i)
{
if(a[i].tip == 0)
{
for(j=0; j<a[i].c; ++j) dp[j] = old[j];
for(j=a[i].c; j<dp.size(); ++j)
dp[j] = max(old[j], old[j-a[i].c] - a[i].v);
}
else
{
for(j=0; j + a[i].c < dp.size(); ++j)
dp[j] = max(old[j], old[j+a[i].c] + a[i].v);
for(; j < dp.size(); ++j)
dp[j] = old[j];
}
swap(dp, old);
}
cout << ( *max_element(old.begin(), old.end()) ) << '\n';
}
int main()
{
// freopen("input", "r", stdin);
cin.tie(0); cin.sync_with_stdio(false);
int i, C, F, V;
cin >> n;
for(i=1; i<=n; ++i)
{
cin >> C >> F >> V;
a[i] = {C, V, F, 0};
}
cin >> m;
for(i=1; i<=m; ++i)
{
cin >> C >> F >> V;
a[i+n] = {C, V, F, 1};
}
n += m;
sort(a+1, a+n+1, [] (ev x, ev y)
{
if(x.f != y.f) return x.f > y.f;
return x.tip < y.tip;
}
);
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'void solve()':
clo.cpp:29:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=a[i].c; j<dp.size(); ++j)
~^~~~~~~~~~
clo.cpp:34:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0; j + a[i].c < dp.size(); ++j)
~~~~~~~~~~~^~~~~~~~~~~
clo.cpp:37:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; j < dp.size(); ++j)
~~^~~~~~~~~~~
# | 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... |