The general idea of this question is that to calculate how many points are deducted at least, we need to arrange the jobs with the most points deducted before the last time. If there are as many points to be deducted, it is necessary to schedule a tight period of time first. Therefore, the scores are first deducted in descending order. If the scores of the two courses are the same, the scores are sorted in descending order based on their end time! Then arrange it! [Cpp] # include <stdio. h> # include <stdlib. h> # include <string. h> # define N 1000 int f [N + 5]; struct T {int deadline; int score;} homework [N + 5]; int cmp (const void *, const void * B) {if (* (struct T *) ). score! = (* (Struct T *) B ). score) return (* (struct T *) B ). score-(* (struct T *) ). score; else return (* (struct T *) ). deadline-(* (struct T *) B ). deadline;} int main () {int C, n, I, j, sum; scanf ("% d", & C); while (C --) {memset (f, 0, sizeof (f); scanf ("% d", & n); for (I = 0; I <n; I ++) scanf ("% d ", & homework [I]. deadline); for (I = 0; I <n; I ++) scanf ("% d", & homework [I]. score); qsort (homework, n, sizeof (homework [0]), cmp); for (I = 0, sum = 0; I <n; I ++) {for (j = homework [I]. deadline; j> 0; j --) // check whether the event has been scheduled in the past few days from the deadline. {if (f [j] = 0) {f [j] = 1; break;} if (j = 0) // if there is no spare time until the end of the process, you can only deduct sum + = homework [I]. score;} printf ("% d \ n", sum);} return 0 ;}