In a city there is n bus drivers. Also there is n morning bus routes & N afternoon bus routes with various lengths. Each driver is assigned one morning Route & one evening route. For any driver, if-his-total route length-a day exceeds D, he-has-to-be-paid overtime for every hour after th E First D hours at a flat R taka/hour. Your task is to assign one morning Route & one evening route to all bus driver so, the total overtime amount The authority is minimized. |
The first line of all test case has three integers n, D and R, as described above. In the second line, there is n space separated integers which is the lengths of the morning routes given in met ERs. Similarly the third line has n space separated integers denoting the evening route lengths. The lengths is positive integers less than or equal to 10000. The end of input is denoted by a case with three 0 s. |
Problem Setter:mohammad Mahmudur Rahman Problem Solving Ideas: First determine the program cycle conditions, set up two arrays A and B respectively to store the morning and evening route length. Using the sort function to sort a arrays in small to large order, redefine the sort function so that it can arrange B arrays in order from large to small. Define a Do function, in this function is the function of the minimum number of a array plus b array of the maximum value, so always add, and every time after the addition to determine whether the sum of the result is greater than D, if more than the journey will be more than the distance of the r, otherwise not. and use a t to accumulate the total amount of extra money that needs to be paid. Finally, this function returns a minimum amount of money t that needs to be paid. Call this function in the main function to solve the minimum amount of money that needs to be paid. 1#include <iostream>2#include <stdio.h>3#include <algorithm>4 using namespacestd;5 Const intmaxn= the;6 intA[MAXN],B[MAXN];7 BOOLFunintAintb)8 {9 returnA>b;Ten } One intDo (int*a,int*b,intNintDintR) A { - ints,t=0; - for(intj=0; j<n;j++) the { -s=a[j]+B[j]; - if(s>d) -t=t+ (s-d) *R; + } - returnT; + } A intMain () at { - intN,d,r; - while(SCANF ("%d%d%d", &n,&d,&r) &&n&&d&&R) - { - for(intI=0; i<n;i++) -scanf"%d",&a[i]); in - for(intk=0; k<n;k++) toscanf"%d",&b[k]); + -Sort (a,a+n); theSort (b,b+n,fun); *printf"%d\n", Do (a,b,n,d,r)); $ }Panax Notoginseng return 0; -} View Code |