이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plpl;
ll N, S;
const int MAXN = 100004;
plpl A[MAXN];
bool cmp1 (plpl a, plpl b) {
return a.second.first*b.second.second > b.second.first*a.second.second;
}
ll scam1(ll s) {
sort(A, A+N, cmp1);
ll ans = 0;
for (int i = 0; i < N; ++i) {
ll k = min(A[i].first, S/A[i].second.second);
ans += k*A[i].second.first;
s -= k*A[i].second.second;
}
return ans;
}
bool cmp2 (plpl a, plpl b) {
return a.second.first > b.second.first;
}
ll scam2 (ll s) {
sort(A, A+N, cmp1);
ll ans = 0;
for (int i = 0; i < N; ++i) {
if (A[i].second.second > S) continue;
ll k = min(A[i].first, S/A[i].second.second);
ans += k*A[i].second.first;
s -= k*A[i].second.second;
}
return ans;
}
bool cmp3 (plpl a, plpl b) {
return a.second.second < b.second.second;
}
ll scam3 (ll s) {
sort(A, A+N, cmp1);
ll ans = 0;
for (int i = 0; i < N; ++i) {
if (A[i].second.second > S) continue;
ll k = min(A[i].first, S/A[i].second.second);
ans += k*A[i].second.first;
s -= k*A[i].second.second;
}
return ans;
}
int main() {
scanf("%lld%lld", &S, &N);
for (int i = 0; i < N; ++i) {
//V, W, K
scanf("%lld%lld%lld", &A[i].second.first, &A[i].second.second, &A[i].first);
}
printf("%lld\n", min({scam1(S), scam2(S), scam3(S)}));
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%lld%lld", &S, &N);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
knapsack.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%lld%lld%lld", &A[i].second.first, &A[i].second.second, &A[i].first);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |