import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
/**
* @author 罗有冠
* @date 2022/11/04 0:36
*/
class Main {
static class Job {
int benefit;
int time;
public Job(int benefit, int time) {
this.benefit = benefit;
this.time = time;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] timeList = new int[n];
int[] benefitList = new int[n];
Job[] jobs = new Job[n];
for (int i = 0; i < n; i++) {
timeList[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
benefitList[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
jobs[i] = new Job(benefitList[i], timeList[i]);
}
// 按时间从小到大排序,时间相同按收益从大到小排
Arrays.sort(jobs, new Comparator<Job>() {
@Override
public int compare(Job o1, Job o2) {
if (o1.time == o2.time) {
return o2.benefit - o1.benefit;
} else {
return o1.time - o2.time;
}
}
});
int ans = 0;
int i = 0;
while (i < n) {
// 先选当前的
ans += jobs[i].benefit;
// 当前时间
int time = jobs[i].time;
// 找到下一个时间
i++;
while (i < n && jobs[i].time == time) {
i++;
}
}
System.out.print(ans);
}
}
10346 带价值的作业安排问题
最新推荐文章于 2024-05-30 16:17:47 发布