이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nemeshay ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define allr(pon) pon.rbegin(), pon.rend()
#define all(pon) pon.begin(), pon.end()
#define nosolve cout << "-1\n"
#define YES cout << "YES\n"
#define Yes cout << "Yes\n"
#define pii pair <int, int>
#define OK cout << "OK\n"
#define Ok cout << "Ok\n"
#define NO cout << "NO\n"
#define No cout << "No\n"
#define pf push_front
#define int long long
#define pb push_back
#define sigma signed
#define sc second
#define fr first
using namespace __gnu_pbds;
using namespace std;
const int N = 1e5 + 20, INF = 1e9 + 7;
int dp[N];
sigma main(){
nemeshay
int n, s, mx = 0;
cin >> s >> n;
if (n == 1) {
int x, y, k;
cin >> x >> y >> k;
cout << min(k, s / y) * x;
return 0;
}
vector <pii> pon;
for (int i = 0; i < n; i++) {
int x, y, k;
cin >> x >> y >> k;
pon.pb({x, y});
for (int j = 1; j < min(s, k); j++) pon.pb({x, y});
}
for (int i = 1; i <= s; i++) dp[i] = INF;
for (int i = 0; i < pon.size(); i++) {
for (int j = s; j >= pon[i].sc; j--) {
if (dp[j - pon[i].sc] != INF) {
if (dp[j] == INF) dp[j] = pon[i].fr + dp[j - pon[i].sc];
else dp[j] = max(dp[j], pon[i].fr + dp[j - pon[i].sc]);
mx = max(mx, dp[j]);
}
}
}
cout << mx;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:44: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]
44 | for (int i = 0; i < pon.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... |