이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nline "\n"
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const int N = 0;
void Solve()
{
int s, n;
cin >> s >> n;
vector<pair<int, int>> a;
a.push_back({0, 0});
for (int i = 0; i < n; ++i)
{
int x, y, z;
cin >> x >> y >> z;
while (z--)
{
a.push_back({x, y});
}
}
n=a.size();
vector<vector<int>> dp(n + 1, vector<int>(s + 1, -INF));
// vector<int> dp(s + 1, -INF);
dp[0][0] = 0;
for (int i = 1; i <= a.size(); ++i)
{
for (int j = 0; j < s + 1; ++j)
{
dp[i][j]=dp[i-1][j];
if (j - a[i].second >= 0)
{
dp[i][j] = max(dp[i][j], dp[i-1][j - a[i].second] + a[i].first);
}
}
}
int ans = 0;
for (int i = 0; i < s+1; ++i)
{
ans = max(ans, dp[n][i]);
}
cout << ans << nline;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
int t = 1;
while (t--) Solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'void Solve()':
knapsack.cpp:31:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 1; i <= a.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... |