# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1179576 | pete555 | Knapsack (NOI18_knapsack) | C++17 | 42 ms | 2124 KiB |
#include<bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define ll long long
#define pb push_back
#define pf push_front
void fileIO(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
const int MOD = 1e9+7;
int main()
{
cin.tie(0)->sync_with_stdio(false);
//fileIO("");
int S, N;
cin >> S >> N;
map<int,vector<pi>> m;
for(int i = 0; i < N; i++){
int V, W, K;
cin >> V >> W >> K;
m[W].pb({V, K});
}
vector<int> dp(S+1);
for(auto _: m){
sort(_.second.begin(), _.second.end(), greater<pi>());
int W = _.first;
for(int i = S; i >= 0; i--){
int cnt = 0, idx = 0, profit = 0, used = 0;
while((cnt+1)*W <= i and idx < _.second.size()){
cnt++, used++;
profit += _.second[idx].first;
dp[i] = max(dp[i], dp[i-cnt*W] + profit);
if(used == _.second[idx].second){
used = 0;
idx++;
}
}
}
}
cout << dp[S] << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |