Submission #595359

#TimeUsernameProblemLanguageResultExecution timeMemory
595359yaroslav06Knapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <iostream> const int N = 2001, M = 1e5; using namespace std; typedef long long ll; int s, n; pair<int, pair<int, int>> d[M]; bool comp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b){ return a.second.first < b.second.first; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dp[N][2]{}; int sm[N]{}; sort(d, d + n, comp); cin >> s >> n; for(int i = 0; i < n; ++i) cin >> d[i].second.first >> d[i].first >> d[i].second.second; for(int i = 0; i < n; ++i){ int k = d[i].second.second, v = d[i].second.first, w = d[i].first; if(sm[v] >= 2000) continue; sm[w] += min(k * 1ll * w, 2000ll); for(int j = 1; j <= k && j * w <= s; ++j) for(int t = s; t - j * w >= 0; --t) dp[t][1] = max(dp[t][1], dp[t - j * w][0] + j * v); for(int j = 0; j <= s; ++j) dp[j][0] = dp[j][1]; } cout << dp[s][0] << '\n'; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:21:5: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   21 |     sort(d, d + n, comp);
      |     ^~~~
      |     qsort