Files
python/GESP/Level5/GESP202309/20230902_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

36 lines
951 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n;
int t[N], r[N];
int ans;
/*
此题采用贪心算法,从最后一个时段开始,选择在该时段内完成有奖励的小游戏中找奖励最大的完成,
时间复杂度为O(N^2)
*/
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> t[i];
for (int i = 1; i <= n; i++)
cin >> r[i];
// 从最后一个时段开始枚举
for (int i = n; i >= 1; i--) {
int k = 0; // 找到i时段之内最大分值位置
int m = 0; // 最大分值
for (int j = 1; j <= n; j++) {
if (t[j] >= i && r[j] > m) {
m = r[j];
k = j;
}
}
if (k != 0) { // 如果找到了
ans += r[k]; // 加分
r[k] = 0; // 清零,防止重复
}
}
cout << ans << endl;
return 0;
}