题目大意:给出n个作业,同时表示有n天.第一行输入表示截止时间(deadline 简称dl)第二行表示如果逾期,要扣除对应的学分。
按分数从大到小排序,如果一样,则dl小的排前面。然后遍历所以科目,如果dl这天没有被占用,则这天完成该作业。
#include <iostream>
#include <queue>
#include <algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAX 1000+10
struct Sub {
int deadline, score;
}sub[MAX];
bool is_used[MAX];
bool cmp(const Sub&a, const Sub&b) {
if (a.score != b.score)
return a.score > b.score;
return a.deadline < b.deadline;
}
int main(void) {
int t;
int n;
scanf("%d", &t);
int all;
int sum;
while (t--) {
all = 0;
memset(is_used, 0, sizeof(is_used));
sum = 0;
scanf("%d", &n);
int a;
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
sub[i].deadline = a;
}
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
sub[i].score = a;
sum += a;
}
sort(sub + 1, sub + 1 + n, cmp);
for (int i = 1; i <= n; i++) {
int day = sub[i].deadline;
if (!is_used[day]) {
is_used[day] = 1;
all += sub[i].score;
}
else {
while (--day) {
if (!is_used[day]) {
is_used[day] = 1;
all += sub[i].score;
break;
}
}
}
}
printf("%d\n", sum - all);
}
return 0;
}
原文地址:https://www.cnblogs.com/tennant/p/8878646.html
时间: 2024-11-12 01:24:40