Title Link: UVA-11389
Test Instructions Description: There are n drivers, n early routes and N night courses, which give each driver an early route and an evening course, so that each morning route and evening course belong to only one driver. If a driver is driving more than D during the morning and evening shifts, then the excess time is paid to the driver at $ r per hour. The minimum cost.
Algorithm analysis: A greedy small problem. The time of the early route is sorted from the big to the small, and the time of the evening course is sorted from small to large, and then it's ready.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <algorithm>7 #defineINF 0x7fffffff8 using namespacestd;9 Const intmaxn= -+Ten;Ten One intN,D,R,AN[MAXN],BN[MAXN]; A - intcmpintIintj) {returnI>J;} - the intMain () - { - while(SCANF ("%d%d%d", &n,&d,&r)! =EOF) - { + if(n==0&& d==0&& r==0) Break; - for(intI=0; i<n; i++) scanf ("%d",&an[i]); + for(intI=0; i<n; i++) scanf ("%d",&bn[i]); A intans=0; atSort (an,an+n); -Sort (bn,bn+n,cmp); - for(intI=0; i<n; i++)if(an[i]+bn[i]>d) ans+= (an[i]+bn[i]-d) *R; -printf"%d\n", ans); - } - return 0; in}
UVA 11389 The Bus Driver problem greedy water problem