Submission #848691

#TimeUsernameProblemLanguageResultExecution timeMemory
848691vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
4 ms600 KiB
//#pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("avx2,tune=native") #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; typedef long long ll; //template <typename T> //using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef pair<int,int> pii; const int arr = 2e3+1; const ll mod = 1e9+7; const ll maxv = 1e18+1; #define int long long #define fi first #define se second #define vi vector<int> #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define no "NO\n" #define yes "YES\n" #define ld long double #define mat vector<vector<ll>> int s, n, dp[30001]; pair<pii, int> a[arr]; vector<pii> tmp; int cnt[arr]; bool cmp(pair<pii, int> c, pair<pii, int> d){ return (c.fi.fi > d.fi.fi); } void read(){ cin >> s >> n; for(int i = 1; i <= n; ++i){ cin >> a[i].fi.fi >> a[i].fi.se >> a[i].se; } sort(a+1, a+n+1, cmp); for(int i = 1; i <= n; ++i){ int cur = cnt[a[i].fi.se]; for(int j = 1; j <= min(a[i].se, (s/a[i].fi.se)-cur); ++j){ cnt[a[i].fi.se]++; tmp.pb(a[i].fi); } } } void solve(){ int ans = 0; for(auto id : tmp){ //cout << id.fi << " " << id.se << endl; int v = id.fi, w = id.se; for(int j = s; j >= w; --j){ dp[j] = max(dp[j], dp[j-w]+v); ans = max(ans, dp[j]); } } cout << ans; } signed main(){ cin.tie(nullptr)->sync_with_stdio(false); read(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...