UVa 11389 - The Bus Driver Problem 难度:0

题目

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


题意

n个司机,n个白天路线,n个晚上路线,要求每个司机一个白天一个晚上路线。设司机2个路线所需时间超出d部分为加班工时,需额外给r元/h。问总加班支出最小是多少。

 

思路

明显,要分的均匀。一个数组大到小,一个数组小到大,依次序组合即可

 

代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 1e3 + 3;
typedef pair<int, int> Pair;
int a[MAXN];
int b[MAXN];
int n, d, r;
int main() {
    int T;
    //scanf("%d", &T);
    freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
    //freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
    for (int ti = 1; scanf("%d%d%d", &n, &d, &r) == 3 && n; ti++) {
        for (int i = 0; i < n; i++) {
            scanf("%d", a + i);
        }
        sort(a, a + n);
        for (int i = 0; i < n; i++) {
            scanf("%d", b + i);
        }
        sort(b, b + n);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans += max(0, a[i] + b[n - 1 - i] - d);
        }
        printf("%d\n", ans * r);
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/xuesu/p/10673482.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值