UVa 11389 – The Bus Driver Problem

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n,d,r,i,overtime,temp,morning[105],evening[105];

    while (true){
        cin>>n>>d>>r;
        if (!n || !d || !r)return 0;

        for (i = 0 ; i < n ; i ++)
            cin>>morning[i];
        for (i = 0 ; i < n ; i ++)
            cin>>evening[i];

        sort(morning,morning+n);
        sort(evening,evening+n);

        overtime = 0;
        for (i = 0 ; i < n ; i ++){
            temp = morning[i]+evening[n-i-1];
            if (temp > d)
                overtime+=r*(temp-d);

        }
        cout<<overtime<<endl;

    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s