| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1321948 | jim_x | Knapsack (NOI18_knapsack) | C++17 | 1095 ms | 608 KiB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
void baseIO(string s = ""){
ios_base::sync_with_stdio(0);
cin.tie(0);
if (s.size()){
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
}
int main() {
baseIO();
int s, n;
cin >> s >> n;
vector<multiset<int>> by_weight(s + 1);
for (int i = 0; i < n; i++){
int a, b, c;
cin >> a >> b >> c;
c = min(c, s / b);
while (c--){
by_weight[b].insert(a);
if (by_weight[b].size() > s / b) by_weight[b].erase(by_weight[b].begin());
}
}
int dp[s + 1]{};
for (int w = 1; w <= s; w++){
for (auto &val : by_weight[w]){
for (int pos = s; pos >= w; pos--) dp[pos] = max(dp[pos], dp[pos - w] + val);
}
}
cout << *max_element(dp, dp + s + 1);
return 0;
}
컴파일 시 표준 에러 (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... | ||||
