UVA 11389 The Bus Driver problem greedy water problem

Source: Internet
Author: User

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

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.