제출 #976277

#제출 시각아이디문제언어결과실행 시간메모리
976277vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
59 ms38236 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define fi first #define sec second #define pii pair<ll,ll> const ll N = 1e5 + 5; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); ll tc = 1; // cin >> tc; while(tc--){ ll s,n; cin >> s >> n; vector<ll>v(n+5), w(n+5), k(n+5); vector<pii>vec[s+5]; for(int i=1;i<=n;i++){ ll a,b,c; cin >> a >> b >> c; vec[b].pb({a,c}); } for(int i=1;i<=s;i++) sort(vec[i].begin(), vec[i].end(), greater<pii>()); vector<vector<ll>>dp(s+5, vector<ll>(s+5)); for(int i=1;i<=s;i++){ for(int j=1;j<=s;j++){ dp[i][j] = dp[i-1][j]; if(vec[i].size() == 0) continue; ll cnt = 0, cur = 0; for(auto x : vec[i]){ if(cnt > j) break; ll tmp = x.sec; for(int k=0;k<x.sec;k++){ cnt += i; cur += x.fi; if(cnt > j) break; dp[i][j] = max(dp[i][j], dp[i-1][j-cnt] + cur); } } } } // for(int i=1;i<=s;i++){ // for(int j=1;j<=s;j++) cout << dp[i][j] << " "; // cout << endl; // } cout << dp[s][s] << endl; } }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:32:9: warning: unused variable 'tmp' [-Wunused-variable]
   32 |      ll tmp = x.sec;
      |         ^~~
#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...