제출 #909844

#제출 시각아이디문제언어결과실행 시간메모리
909844oblantisKnapsack (NOI18_knapsack)C++17
100 / 100
45 ms3856 KiB
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back #define ss second #define ff first #define vt vector using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int, int> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int inf = 1e9; const int mod = 1e9+7; const int maxn = 1e5 + 1; ll dp[2001]; void solve() { int s, n; cin >> s >> n; vt<pii> hv[2001]; for(int i = 0, v, w, k; i < n; i++){ cin >> v >> w >> k; k = min(k, s / w); hv[w].pb({v, k}); } for(int i = 1; i <= s; i++){ sort(rall(hv[i])); int cnt = 0; for(size_t j = 0; j < hv[i].size(); j++){ while(hv[i][j].ss--){ for(int o = s; o >= i; o--){ dp[o] = max(dp[o - i] + hv[i][j].ff, dp[o]); } cnt++; if(cnt * i >= s)break; } if(cnt * i >= s)break; } } cout << dp[s]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int times = 1; //cin >> times; for(int i = 1; i <= times; i++) { 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...