Submission #963170

# Submission time Handle Problem Language Result Execution time Memory
963170 2024-04-14T16:08:50 Z Quanmapne Knapsack (NOI18_knapsack) C++14
100 / 100
51 ms 5212 KB
#include<bits/stdc++.h>
#define ll long long
#define file "knapsack"
using namespace std;
const int maxN = 1e5 + 5;
int t, n, s;
int v[maxN], w[maxN], k[maxN];
ll dp[2005];
vector< pair<int, int> > obj[maxN];

void solve(){
    for (int i = 1; i <= s; ++i){
        if (obj[i].size() == 0)
            continue;

        sort(obj[i].begin(), obj[i].end(), greater<pair<int, int>>());
        int id = 0;

        for (int j = 1; j * i <= s; ++j){

            if (id >= obj[i].size())
                break;

            for (int f = s; f >= i; --f){
                    dp[f] = max(dp[f], dp[f - i] + obj[i][id].first);
            }
            --obj[i][id].second;
            if (obj[i][id].second == 0)
                ++id;
        }
    }
    cout << dp[s];
}

signed main(){
//    freopen(file".inp", "r", stdin);
//    freopen(file".out", "w", stdout);
    ios_base::sync_with_stdio(false); cin.tie(0);
    t = 1;
    while (t){
        cin >> s >> n;
        for (int i = 1; i <= n; ++i){
            cin >> v[i] >> w[i] >> k[i];
            obj[w[i]].push_back({v[i], k[i]});
        }

        solve();

        --t;
    }

    return 0;
}

Compilation message

knapsack.cpp: In function 'void solve()':
knapsack.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |             if (id >= obj[i].size())
      |                 ~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2648 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 4 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2704 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2648 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 4 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2704 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 27 ms 4824 KB Output is correct
36 Correct 27 ms 4824 KB Output is correct
37 Correct 25 ms 4836 KB Output is correct
38 Correct 26 ms 4832 KB Output is correct
39 Correct 26 ms 4864 KB Output is correct
40 Correct 49 ms 5168 KB Output is correct
41 Correct 31 ms 4996 KB Output is correct
42 Correct 39 ms 5184 KB Output is correct
43 Correct 51 ms 5172 KB Output is correct
44 Correct 44 ms 5172 KB Output is correct
45 Correct 26 ms 5212 KB Output is correct
46 Correct 26 ms 4804 KB Output is correct
47 Correct 28 ms 5212 KB Output is correct
48 Correct 36 ms 4956 KB Output is correct
49 Correct 24 ms 5212 KB Output is correct
50 Correct 44 ms 4840 KB Output is correct