제출 #964181

#제출 시각아이디문제언어결과실행 시간메모리
964181stdfloatKnapsack (NOI18_knapsack)C++17
12 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ff first #define ss second #define pii pair<int, int> struct stdfloat { int v, w, k; }; bool cmp(stdfloat a, stdfloat b) { if (a.v * b.w != b.v * a.w) return a.v * b.w > b.v * a.w; return a.w < b.w; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int s, n; cin >> s >> n; vector<stdfloat> a(n); for (auto &i : a) cin >> i.v >> i.w >> i.k; sort(a.begin(), a.end(), cmp); ll ans = 0; for (auto i : a) { ans += (ll)min(s / i.w, i.k) * i.v; s -= min(s / i.w, i.k) * i.w; } 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...