uva 11389 - The Bus Driver Problem(贪心)

来源:互联网 发布:java有链表吗 编辑:程序博客网 时间:2024/05/24 02:38

题目链接:uva 11389 - The Bus Driver Problem


题目大意:有n个司机,n条下午路线和n条晚上路线,先在要给每个司机安排一条下午路线和一条晚上路线,如果司机的工作时间超过d,则要按照每小时r元增加加班费,问最少需支付多少加班费。


解题思路:贪心,下午最大的搭配晚上最小的,一次类推。


#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N = 105;int n, d, r, after[N], even[N];void init() {for (int i = 0; i < n; i++) scanf("%d", &after[i]);for (int i = 0; i < n; i++) scanf("%d", &even[i]);sort(after, after + n);sort(even, even + n);}int solve() {int ans = 0, p = 0;for (int i = n - 1; i >= 0; i--) {int c = after[i] + even[p++];if (c > d) ans += c - d;}return ans;}int main () {while (scanf("%d%d%d", &n, &d, &r) == 3 && n && d && r) {init();printf("%d\n", solve() * r);}return 0;}




1 0
原创粉丝点击