'commit'
This commit is contained in:
38
GESP/Level5/GESP202309/20230902_2.cpp
Normal file
38
GESP/Level5/GESP202309/20230902_2.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 510;
|
||||
/*
|
||||
贪心思路:
|
||||
先将游戏按分值从大到小排列,然后给最大分值的游戏安排在时效内尽可能晚的时段完成,
|
||||
安排完所有游戏,对于能安排的游戏,计分,即为答案
|
||||
|
||||
7
|
||||
4 2 4 3 1 4 6
|
||||
70 60 50 40 30 20 10
|
||||
*/
|
||||
int n;
|
||||
struct Node {
|
||||
int T, R;
|
||||
} a[N];
|
||||
bool cmp(Node x, Node y) { return x.R > y.R; }
|
||||
bool b[N];
|
||||
int sum;
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i++)
|
||||
cin >> a[i].T;
|
||||
for (int i = 0; i < n; i++)
|
||||
cin >> a[i].R;
|
||||
sort(a, a + n, cmp);
|
||||
|
||||
for (int i = 0; i < n; i++) // 小游戏
|
||||
for (int t = a[i].T - 1; t >= 0; t--) // 时间段
|
||||
if (!b[t]) { // 是不是被占用
|
||||
b[t] = true;
|
||||
sum += a[i].R;
|
||||
break;
|
||||
}
|
||||
|
||||
cout << sum << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user