Iiuc ONLINE CONTEST 2008/uva 11389 the bus Driver Problem: Greed

Source: Internet
Author: User

11389-the Bus Driver Problem

Time limit:1.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=2384

In a city there are n bus drivers. Also There are 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 him total route length for a day exceeds D, he has to is paid overtime for every hour after the Hours at a flat R taka/hour. Your task is to assign one morning Route & one evening route to all bus driver so this total overtime amount The authority has to pay is minimized.

Input

The "a" of each test case has three integers n, D and R, as described above. In the second line, there are n space separated integers which the are of the lengths morning. Similarly the third line has n space separated integers denoting the evening route. The lengths are positive integers less than or equal to 10000. The end of the input was denoted by a case with three 0 s.

Output

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

Constraints

-1≤n≤100

-1≤d≤10000

-1≤r≤5

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Sample Input

2 20 5

10 15

10 15

2 20 5

10 10

10 10

0 0 0

Output for Sample Input

50

0

An increase of one minus is necessarily optimal, which can be disproved by exchanging the position of two elements.

Complete code:

/*0.016s*/
    
#include <cstdio>  
#include <algorithm>  
#include <functional>  
using namespace Std;  
    
int a[105], b[105];  
    
int main ()  
{  
    int n, D, r, Sum, temp;  
    while (scanf ("%d%d%d", &n, &d, &r), N)  
    {for  
        (int i = 0; i < n; ++i)  
            scanf ("%d", &a[i]);  
        for (int i = 0; i < n; ++i)  
            scanf ("%d", &b[i]);  
        Sort (A, a + N);  
        Sort (b, B + N, greater<int> ());  
        sum = 0;  
        for (int i = 0; i < n; ++i)  
        {  
            temp = A[i] + b[i]-D;  
            if (temp > 0) sum + + temp;  
        }  
        printf ("%d\n", Sum * r);  
    }  
    return 0;  
}

Author: csdn Synapse7

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.