Submission #1290085

#TimeUsernameProblemLanguageResultExecution timeMemory
1290085ghammazhassanKnapsack (NOI18_knapsack)C++20
100 / 100
103 ms125920 KiB
// #include <bits/stdc++.h> #include <iostream> #include <cmath> #include <algorithm> #include <map> #include <unordered_map> #include <vector> #include <iomanip> #include <string> #include <queue> #include <set> #include <deque> using namespace std; // #define int long long #define endl "\n" #define fi first #define se second const int M=1e9+7; // const int inf = 1e14; const int LOG=18; const int N=2e3+5; int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r; int dp[8*N][N]; void solve(){ int s; cin >> s >> n; vector<vector<int>>a(s+1); vector<vector<int>>in(n); for (int i=0;i<n;i++){ cin >> x >> y >> z; z=min(z,s/y); in[i]={x,y,z}; } sort(in.rbegin(),in.rend()); for (int i=0;i<n;i++){ int v=in[i][0]; int w=in[i][1]; int k=in[i][2]; while (k-- and a[w].size()<s/w){ a[w].push_back(v); } } int j=1; int ans=0; for (int i=1;i<=s;i++){ for (int l:a[i]){ for (int w=i;w<=s;w++){ dp[j][w]=max(dp[j-1][w],dp[j-1][w-i]+l); ans=max(ans,dp[j][w]); } j++; } } cout << ans << endl; } signed main() { ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE cout << fixed << setprecision(9); srand(time(0)); // int t=1; // cin >> t; for (int _=1;_<=t;_++){ solve(); q++; } }
#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...