제출 #1139491

#제출 시각아이디문제언어결과실행 시간메모리
1139491Daniel_1997Knapsack (NOI18_knapsack)C++20
73 / 100
1096 ms27540 KiB
#include<bits/stdc++.h> using namespace std; //\\ PRINCIPAL \\// #define int long long #define mod 800000007 #define ios ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0) //\\ STL \\// #define pb push_back #define fr first #define sc second #define all(x) x.begin(), x.end() int32_t main() { ios; int s,n; cin >> s >> n; vector< pair< int, pair< int,int> > >v(n); vector< pair< int, pair< int,int> > >v2; for(int l = 0; l < v.size(); l++) { cin >> v[l].fr >> v[l].sc.fr >> v[l].sc.sc; if(v[l].sc.sc > s)v[l].sc.sc = s; pair< int, pair< int,int> > i = v[l]; int aux = i.sc.sc; for(int j = 0; j < 13; j++) { int aux2 = (1 << j); if(aux >= aux2) { v2.pb({i.fr * aux2,{i.sc.fr * aux2,1}}); aux -= aux2; } } if(aux == 0)continue; v2.pb({i.fr * aux,{i.sc.fr * aux,1}}); } vector<int>dp(s + 1,0); int maxx=0; for(pair< int, pair< int,int> > i : v2) { for(int j = s; j >= i.sc.fr; j--) { dp[j] = max(dp[j],dp[j - i.sc.fr] + i.fr); maxx = max(maxx,dp[j]); } } cout << maxx << endl; 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...