Submission #908555

#TimeUsernameProblemLanguageResultExecution timeMemory
908555Ronak1808Knapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <chrono> #define int long long using namespace __gnu_pbds; using namespace std; using namespace std::chrono; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; const int MOD = 998244353; int add(int x, int y){ return ((x + y) % MOD + MOD) % MOD; } int mul(int x, int y){ return x * 1ll * y % MOD; } int binpow(int x, int y){ int z = 1; while(y){ if(y % 2 == 1) z = mul(z, x); x = mul(x, x); y /= 2; } return z; } int inv(int x){ return binpow(x, MOD - 2); } int divide(int x, int y){ return mul(x, inv(y)); } signed main(){ int s, n; cin>>s>>n; map<int, vector<pair<int, int>>>mp; for(int i = 1;i<=n;i++){ int v, w, k; cin>>v>>w>>k; mp[w].push_back({v, k}); } for(auto &x : mp){ sort((x.second).begin(), (x.second).end(), greater<pair<int, int>>()); } vector<vector<int>>dp(int(mp.size()), vector<int>(s+1, 0)); auto it = mp.begin(); int res= 0; for(int i = 0;i<int(mp.size());i++){ for(int use = 0; use <= s; use++){ int sum = 0; int val = 0; dp[i][use] = (i-1 >= 0?dp[i-1][use]:0); for(auto &x : it->second){ val += x.first; sum += it->first; if(sum > use)break; dp[i][use] = max(dp[i][use], val + (i-1 >= 0?dp[i-1][use - sum]:0)); } res = max(res, dp[i][use]); } it++; } cout<<res<<"\n"; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:5:13: error: expected primary-expression before 'long'
    5 | #define int long long
      |             ^~~~
knapsack.cpp:47:27: note: in expansion of macro 'int'
   47 |     vector<vector<int>>dp(int(mp.size()), vector<int>(s+1, 0));
      |                           ^~~
knapsack.cpp:5:13: error: expected primary-expression before 'long'
    5 | #define int long long
      |             ^~~~
knapsack.cpp:50:21: note: in expansion of macro 'int'
   50 |     for(int i = 0;i<int(mp.size());i++){
      |                     ^~~
knapsack.cpp:50:21: error: expected ';' before 'long'
   50 |     for(int i = 0;i<int(mp.size());i++){
      |                     ^
      |                     ;
knapsack.cpp:5:13: error: expected primary-expression before 'long'
    5 | #define int long long
      |             ^~~~
knapsack.cpp:50:21: note: in expansion of macro 'int'
   50 |     for(int i = 0;i<int(mp.size());i++){
      |                     ^~~
knapsack.cpp:50:21: error: expected ')' before 'long'
   50 |     for(int i = 0;i<int(mp.size());i++){
      |        ~            ^
      |                     )
knapsack.cpp:5:13: error: expected primary-expression before 'long'
    5 | #define int long long
      |             ^~~~
knapsack.cpp:50:21: note: in expansion of macro 'int'
   50 |     for(int i = 0;i<int(mp.size());i++){
      |                     ^~~
knapsack.cpp:50:36: error: 'i' was not declared in this scope; did you mean 'it'?
   50 |     for(int i = 0;i<int(mp.size());i++){
      |                                    ^
      |                                    it