Title: There are n morning tasks and PM tasks assigned to the driver, if the total work time exceeds D, the part to be paid overtime;
Now let you schedule tasks and ask for the minimum overtime cost.
Analysis: Greed. Each of the two tasks is sorted by increment and decrement order, each corresponding to a set of side numbers.
The two sets of paired elements in the sequence are m1,a1,m2,a2 and m1≤m2,a1≤a2;
The pairing method <m1,a2>,<m2,a1> is better than <m1,a1>,<m2,a2> (less likely to be wasted).
Description: (⊙_⊙).
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int morni[101];int after[101];int cmp1 (int a, int b) {return a < b; }int CMP2 (int a, int b) {return a > B;} int main () {int n,d,r;while (~scanf ("%d%d%d", &n,&d,&r) && N) {for (int i = 0; i < n; + + i) scanf ("% D ", &morni[i]); for (int i = 0; i < n; + + i) scanf ("%d ", &after[i]); sort (Morni, morni+n, CMP1); sort (after, after+ n, cmp2); int sum = 0;for (int i = 0; i < n; + + i) if (Morni[i]+after[i] > D) sum + = r* (morni[i]+after[i]-d);p rintf ( "%d\n", sum);} return 0;}
UVa 11389-the Bus Driver problem