UVa 11389-the Bus Driver problem

Source: Internet
Author: User

Title: There are n morning tasks and PM tasks assigned to the driver, if the total work time exceeds D, the part to be paid overtime;

Now let you schedule tasks and ask for the minimum overtime cost.

Analysis: Greed. Each of the two tasks is sorted by increment and decrement order, each corresponding to a set of side numbers.

The two sets of paired elements in the sequence are m1,a1,m2,a2 and m1≤m2,a1≤a2;

The pairing method <m1,a2>,<m2,a1> is better than <m1,a1>,<m2,a2> (less likely to be wasted).

Description: (⊙_⊙).

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <  Cstdio> #include <cmath>using namespace Std;int morni[101];int after[101];int cmp1 (int a, int b) {return a < b; }int CMP2 (int a, int b) {return a > B;} int main () {int n,d,r;while (~scanf ("%d%d%d", &n,&d,&r) && N) {for (int i = 0; i < n; + + i) scanf ("% D ", &morni[i]); for (int i = 0; i < n; + + i) scanf ("%d ", &after[i]); sort (Morni, morni+n, CMP1); sort (after, after+ n, cmp2); int sum = 0;for (int i = 0; i < n; + + i) if (Morni[i]+after[i] > D) sum + = r* (morni[i]+after[i]-d);p rintf ( "%d\n", sum);}     return 0;}


UVa 11389-the Bus Driver 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.