제출 #496164

#제출 시각아이디문제언어결과실행 시간메모리
496164f4t4ntKnapsack (NOI18_knapsack)C++11
100 / 100
198 ms36388 KiB
#include <algorithm> #include <cmath> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <iomanip> #include <iterator> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <unordered_set> #include <utility> #include <vector> #define ll long long #define pll pair<ll, ll> #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define vvl vector<vl> #define vvvl vector<vvl> #define vvvvl vector<vvvl> #define vpll vector<pll> #define vvpll vector<vpll> #define plvl pair<ll, vl> #define vplvl vector<plvl> #define sl set<ll> #define spll set<pll> #define vsl vector<sl> #define ssl set<sl> #define plsl pair<ll, sl> #define vplsl vector<plsl> #define msl multiset<ll> #define mspll multiset<pll> #define vb vector<bool> #define vvb vector<vb> #define mll map<ll, ll> #define mlll map<ll, mll> #define mlvl map<ll, vl> #define mlpll map<ll, pll> #define mlvpll map<ll, vpll> #define mlsl map<ll, sl> #define mpllb map<pll, bool> #define vmll vector<mll> #define ql queue<ll> #define qpll queue<pll> #define fl float #define vf vector<fl> #define vvf vector<vf> #define str string #define vstr vector<str> #define mstrl map<str, ll> #define pb push_back #define elif else if #define sz(C) (ll) C.size() #define flip(C) reverse(C.begin(), C.end()) #define ssort(C) sort(C.begin(), C.end()) #define rsort(C) sort(C.begin(), C.end(), greater<pll>()) #define max_elem(C) *max_element(C.begin(), C.end()) #define min_elem(C) *min_element(C.begin(), C.end()) #define FOR(x, e) for(ll x = 0; x < (ll) e; x++) #define FORR(x, e) for(ll x = (ll) e - 1; x >= 0; x--) #define FOB(x, b, e) for(auto x = (ll) b; x != (ll) e; x++) #define FOE(x, e, b) for(auto x = (ll) e - 1; x >= (ll) b; x--) #define FOI(x, e, i) for(ll x = 0; x < (ll) e; x += (ll) i) #define FORE(x, C) for(auto& x : C) using namespace std; int main() { ll S, N; cin >> S >> N; mlvpll W; FOR(n, N) { ll v, w, k; cin >> v >> w >> k; W[w].pb({ v, k }); } ll M = sz(W) + 1; S++; vvl dp(M, vl(S)); ll m = 1; FORE(x, W) { ll w = x.first; vpll &v = x.second; rsort(v); dp[m] = dp[m - 1]; FOR(s, S) { ll i = 1, j = 0, k = 0, p = 0; while(i * w <= s && j < sz(v)) { p += v[j].first; dp[m][s] = max(dp[m][s], dp[m - 1][s - i * w] + p); i++; k++; if(k == v[j].second) { k = 0; j++; } } } m++; } cout << max_elem(dp[M - 1]) << '\n'; }
#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...