이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, q;
ll maxn = 0;
const ll inf = 1e18;
vector<ll> solve(vector<tuple<ll,ll,ll>> &data, bool mex) {
vector<ll> dp(vector<ll>(maxn + 1,mex ? -inf : inf));
dp[0] = 0;
for (ll i = 1; i <= data.size() ; ++i) {
vector<ll> ndp = dp;
auto [f,c, v] = data[i - 1];
for (ll j = 0; j <= maxn; ++j) {
if (mex) {
if (j - c >= 0 && j - c <= maxn) ndp[j] = max(dp[j],dp[j - c] + v);
} else {
if (j - c >= 0 && j - c <= maxn) ndp[j] = min(dp[j],dp[j - c] + v);
}
}
dp = ndp;
}
return dp;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
vector<tuple<ll,ll,ll>> arr;
ll s1 = 0, s2 = 0;
for (ll i = 0; i < n; ++i) {
ll c, f, v; cin >> c >> f >> v;
arr.emplace_back(f,c,-v);
s1 += c;
}
cin >> q;
for (ll i = 0; i < q; ++i) {
ll c, f, v; cin >> c >> f >> v;
arr.emplace_back(f,-c,v);
s2 += c;
}
maxn = max(s2, s1);
sort(arr.begin(), arr.end());
reverse(arr.begin(), arr.end());
auto c = solve(arr, true);
ll ans = 0;
for (int i = 0; i <= maxn; ++i) {
ans = max(c[i],ans);
}
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'std::vector<long long int> solve(std::vector<std::tuple<long long int, long long int, long long int> >&, bool)':
clo.cpp:11:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (ll i = 1; i <= data.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... |