From c7114f4976f00ee540cd76e9f8919ee639fa555c Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 25 Aug 2024 23:20:42 +0800 Subject: [PATCH] =?UTF-8?q?B3872=20[GESP202309=20=E4=BA=94=E7=BA=A7]=20?= =?UTF-8?q?=E5=B7=A7=E5=A4=BA=E5=A4=A7=E5=A5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/174742232 --- Luogu/B3872/B3872.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Luogu/B3872/B3872.cpp diff --git a/Luogu/B3872/B3872.cpp b/Luogu/B3872/B3872.cpp new file mode 100644 index 00000000..0f1e66de --- /dev/null +++ b/Luogu/B3872/B3872.cpp @@ -0,0 +1,48 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 505; + +int n, ans; +bool t[N]; + +struct node { + int t, r; +} a[N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i].t; + } + + for (int i = 1; i <= n; i++) { + cin >> a[i].r; + } + + std::sort(a + 1, a + 1 + n, [&](const node &a, const node &b) { + return a.r > b.r; + }); + + for (int i = 1; i <= n; i++) { + for (int j = a[i].t; j; j--) { + if (!t[j]) { + t[j] = true; + ans += a[i].r; + break; + } + } + } + + cout << ans << endl; + + return 0; +}