Problem Description
Problem Analysis
To minimize the wasted score
consider sorting by score first
According to the problem, try to schedule assignments as close to the deadline as possible
For example, if the deadline is 4 days away
then consider completing it on day 4; if that doesn’t work, day 3, day 2, …
If it cannot be scheduled, that means this score is wasted
So we can build an array to record whether an assignment is scheduled on a given day
and use it to determine which day the assignment should be scheduled on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node {
int date,score;
} a[1200];
bool cmp(node A,node B) {
if(A.score==B.score)
return A.date>B.date;
else
return A.score>B.score;
}
int flag[1200];
int main() {
int T;
scanf("%d",&T);
while(T--) {
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%d",&a[i].date);
for(int i=0; i<n; i++)
scanf("%d",&a[i].score);
sort(a,a+n,cmp);
int sum=0;
memset(flag,0,sizeof(flag));
for(int i=0; i<n; i++) {
int j;
for(j=a[i].date; j>0; j--) {
if(!flag[j]) {
flag[j]=1;
break;
}
}
if(j==0)
sum+=a[i].score;
}
printf("%d\n",sum);
}
return 0;
}
|