답안 #985751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985751 2024-05-18T16:24:18 Z vjudge1 Knapsack (NOI18_knapsack) C++17
12 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int S, N;
    std::cin >> S >> N;

    std::map<int, std::vector<std::pair<int, int>>> item;
    for (int i = 0; i < N; i++) {
        int v, w, k;
        std::cin >> v >> w >> k;
        
        item[w].push_back({v, k});
    }

    std::vector<i64> dp(1 + S);

    for (auto &[w, vec] : item) {
        for (int j = S; j >= 0; j--) {
            i64 val = 0;
            for (int c = 1, i1 = 0, i2 = 0; c * w <= S; c++) {
                if (i2 == vec[0].second) {
                    i1++, i2 = 0;
                }
                if (i1 == (int)vec.size()) {
                    break;
                }

                auto [v, k] = vec[i1];
                val += v, i2++;

                if (j + c * w <= S) {
                    dp[j + c * w] = std::max(dp[j + c * w], dp[j] + val);
                }
            }
        }
    }

    std::cout << *std::max_element(dp.begin(), dp.end()) << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -