제출 #1085909

#제출 시각아이디문제언어결과실행 시간메모리
1085909themaver1cksKnapsack (NOI18_knapsack)C++14
100 / 100
84 ms35416 KiB
/** 。∠(*・ω・)っ ⌒ 由 ~ (( ,,・з・,, )) _Π_____。 /______/~\ | 田田|門| why im so dumb man >.< **/ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define sz(x) (int)(x).size() #define el "\n" typedef long long ll; typedef pair<int,int> pii; // var dec const int maxn = 2e3 + 3; int n, s; // ds dec // void solve() { cin >> s >> n; map <int, vector<pii>> mp; for (int i=1; i<=n; ++i) { int v, w, k; cin >> v >> w >> k; mp[w].pb({v, k}); } vector <vector<ll>> dp(sz(mp)+3, vector<ll>(s+3, -1)); int i = 1; dp[0][0] = 0; for (auto x: mp) { int w = x.fi; vector <pii> v = x.se; sort(v.begin(), v.end(), greater<pii>()); for (int j=0; j<=s; ++j) { dp[i][j] = dp[i-1][j]; int items = 0; int cur = 0; int copies = v[cur].se; ll profit = 0; while ((items+1)*w <= j && cur < sz(v)) { profit += v[cur].fi; ++items; if (dp[i-1][j-items*w] != -1) dp[i][j] = max(dp[i][j], dp[i-1][j-items*w] + profit); --copies; if (copies == 0) { ++cur; copies = v[cur].se; } } } ++i; } ll ans = 0; for (int j=0; j<=s; ++j) ans = max(ans, dp[sz(mp)][j]); cout << ans << el; } // int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("lmao.inp", "r")) { freopen("lmao.inp", "r", stdin); freopen("lmao.out", "w", stdout); } int t = 1; // cin >> t; while (t--) solve(); return 0; }

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

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen("lmao.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen("lmao.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...