제출 #1261458

#제출 시각아이디문제언어결과실행 시간메모리
1261458limon4ickKnapsack (NOI18_knapsack)C++20
100 / 100
35 ms1624 KiB
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #pragma ("reroll") */ #include <bits/stdc++.h> using namespace std; //#define int long long #define pb push_back #define ins insert #define F first #define S second const int mod = 1e7 + 7,N = 2e3 + 100,mx = (int)(1e6 + 100); vector<pair<int,int>>g[N]; int dp[N]; signed main(){ //freopen("justcoding.in","r",stdin); //freopen("justcoding.out","w",stdout); std::ios::sync_with_stdio(false); cin.tie(0); int n,s; cin >> s >> n; for(int i = 1;i<=n;i++){ int u,w,k; cin >> u >> w >> k; g[w].pb({u,k}); } for(int i = 1;i<=s;i++){ if(!g[i].size()) continue; sort(g[i].rbegin(),g[i].rend()); } for(int i = 1;i<N;i++) dp[i] = -INT_MAX; dp[0] = 0; for(int i = 1;i<=s;i++){ if(g[i].size()==0) continue; for(int x = s;x>=0;x--){ int xz = x; int cnt = 0; int j = 0; int sum = 0; int y = g[i][j].F,y1 = g[i][j].S; while(xz+i<=s){ xz+=i; sum+=y; y1--; if(dp[x]>=0) dp[xz] = max(dp[x]+sum,dp[xz]); if(y1==0) {j++;y = g[i][j].F;y1 = g[i][j].S;} if(j==g[i].size()) break; } } } int ans = 0; for(int i = 0;i<=s;i++){ ans = max(ans,dp[i]); } cout << ans; }
#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...