【Codeforces Round #694 (Div. 2) C】Strange Birthday Party
阿新 • • 發佈:2021-02-07
技術標籤:leetcodealgorithmndk動態規劃jquery
題目連結
翻譯
translation
題解
\(k\) 值比較大(對應的禮物貴)的優先安排小的 \(c\),這樣節省的 \(money\) 最多。
因為每個 \(k\) 都是要滿足的,當然儘可能用便宜點的搪塞最好。。塑料友情。。
程式碼
#include <bits/stdc++.h> #define LL long long using namespace std; const int N = 3e5; int n, m; int c[N+10]; pair<int, int> k[N + 10]; int main() { #ifdef LOCAL_DEFINE freopen("in.txt", "r", stdin); #endif ios::sync_with_stdio(0), cin.tie(0); int T; cin >> T; while (T--) { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> k[i].first; k[i].second = i; } sort(k + 1, k + 1 + n); reverse(k + 1, k + 1 + n); for (int i = 1; i <= m; i++) { cin >> c[i]; } LL sum = 0; int j = 1; for (int i = 1; i <= n; i++) { if (j <= m && j <= k[i].first) { sum += c[j]; j++; } else { sum += c[k[i].first]; } } cout << sum << endl; } return 0; }