이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define LIFESUCKS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ar array
#define fu(i,a,b,c) for(ll i=a;i<=b;i+=c)
#define fd(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
//#define length(x) (int)(x).size()
#define fi first;
#define se second;
#define vt vector
const int mxn = 5e4;
struct o{
ll v, k;
};
bool cmp(o a, o b){
return(a.v > b.v);
}
int s, n;
vt<o>a[2001];
int main(){
LIFESUCKS;
cin >> s >> n;
for(int i = 0; i < n; i++){
ll w, v, k; cin >> v >> w >> k;
a[w].pb({v, k});
}
ll dp[s + 1][s + 1]; memset(dp, 0, sizeof(dp));
for(int i = 0; i <= s; i++)dp[0][i] = 0;
for(int i = 1; i <= s; i++)sort(a[i].begin(), a[i].end(), cmp);
for(int i = 1; i <= s; i++){
int cr = s / i;
for(int j= 1; j <= s; j++)dp[i][j] = dp[i - 1][j];
ll val = 0, cnt = 0;
for(int j = 0; j < a[i].size(); j++){
a[i][j].k = min(cr - cnt, a[i][j].k);
for(int k = 1; k <= a[i][j].k; k++){
val += a[i][j].v; cnt++;
for(int l = cnt * i; l <= s; l++){
dp[i][l] = max(dp[i][l], dp[i - 1][l - cnt * i] + val);
}
}
if(cnt == cr)break;
}
}
ll ans = 0;
for(int i = 1; i <= s; i++)ans = max(ans, dp[s][i]);
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:42:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<o>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int j = 0; j < a[i].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... |