ACM Car travel problem for minimum payment

Source: Internet
Author: User

Description

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.

Input

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.

Output

For each test case, print the minimum possible overtime amount that the authority must pay.

Constraints

-1≤n≤100

-1≤d≤10000

-1≤r≤5

Sample Input

Output for Sample Input

2 20 5

10 15

10 15

2 20 5

10 10

10 10

0 0 0

50

0

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

ACM Car travel problem for minimum payment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.