Submission #982452

# Submission time Handle Problem Language Result Execution time Memory
982452 2024-05-14T09:22:02 Z a_l_i_r_e_z_a Knapsack (NOI18_knapsack) C++17
12 / 100
1 ms 2652 KB
// In the name of God
// Hope is last to die

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC optimize("avx2")

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(xyxy, yxy) (xyxy) = max((xyxy), (yxy))
#define smin(xyxy, yxy) (xyxy) = min((xyxy), (yxy))
#define all(xyxy) (xyxy).begin(), (xyxy).end()
#define len(xyxy) ((int)(xyxy).size())

const int maxn = 1e5 + 5, maxs = 2e3 + 5;
const int inf = 1e9 + 7;
int s, n, dp[maxs];
vector<int> vec[maxs];
vector<pii> a[maxn];

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> s >> n;
    for(int i = 0; i < n; i++){
        int v, w, k; cin >> v >> w >> k;
        smin(k, s);
        a[w].pb(mp(v, k));
    }
    for(int i = 1; i <= s; i++){
        int sz = s / i;
        sort(all(a[i]));
        for(auto [v, k]: a[i]){
            for(int h = 1; h <= k && vec[i].size() < sz; h++) vec[i].pb(v);
        }
    }
    for(int i = 1; i <= s; i++){
        for(auto v: vec[i]){
            for(int j = s; j >= 1; j--){
                if(j - i >= 0) smax(dp[j], v + dp[j - i]);
            }
        }
    }
    cout << dp[s] << '\n';

    return 0;
}

Compilation message

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:45:52: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |             for(int h = 1; h <= k && vec[i].size() < sz; h++) vec[i].pb(v);
      |                                      ~~~~~~~~~~~~~~^~~~
# 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 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 2648 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 2648 KB Output isn't correct
6 Halted 0 ms 0 KB -