11389 - The Bus Driver Problem(贪心)

本文介绍了一种用于比赛配对的算法实现,该算法通过将下午和晚上的比赛时间进行排序来计算总的加班费用。使用C++实现,并利用标准模板库进行数据处理,包括输入输出加速、数组初始化等技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

把下午的时间和晚上的时间分别正序排序和逆序排序。。

/***********************************************
 * Author: fisty
 * Created Time: 2015/2/10 14:49:31
 * File Name   : uva11389.cpp
 *********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define Memset(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
#define MAX_N 110
int n, d, r;
int afternoon[MAX_N], evening[MAX_N];
int ans[MAX_N];

bool cmp(int a, int b){
    return a > b;
}

int main() {
    //freopen("in.cpp", "r", stdin);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> d >> r){
        if(!n && !d && !r) break;
        FOR(i, 0 , n){
            cin >> afternoon[i];
        }
        FOR(i, 0, n){
            cin >> evening[i];
        }
        sort(afternoon, afternoon + n);
        sort(evening, evening + n, cmp);
        int ans = 0;
        for(int i = 0;i < n; i++){
            if(afternoon[i] + evening[i] > d){
                ans += r*(afternoon[i] + evening[i] - d);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值