码迷,mamicode.com
首页 > 其他好文 > 详细

安装服务 LA 4850

时间:2019-09-22 21:35:21      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:ring   opened   string   bsp   单位   none   工程   pop   tor   

题目大意

工程师需要安装n个服务,其中的第i个服务Ji需要Si个单位的时间,截止时间为Di,如果在截止时间之前完成任务不会收到惩罚,如果超时惩罚时间时Ci-di意思就是超时多少惩罚值就越大,从t=0时刻开始,找到两个惩罚值之和最小的任务。

分析

技术图片
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 800000 + 10;
struct order {
    int s, t;
    bool operator < (const order & a) const {
        return s < a.s;
    }
}ord[maxn];
priority_queue<order>q;
bool cmp(const order &a, const order & b) {
    return a.t < b.t || (a.t == b.t && a.s < b.s);
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin>>ord[i].s>>ord[i].t;
        }
        sort(ord, ord + n, cmp);

        while (!q.empty())q.pop();
        int cur = 0;
        for (int i = 0; i < n; ++i) {
            if (cur + ord[i].s <= ord[i].t) {
                q.push(ord[i]);
                cur += ord[i].s;
            }
            else {
                if (q.empty())continue;
                order u = q.top();
                if (u.s > ord[i].s) {
                    cur = cur - u.s + ord[i].s;
                    q.pop();
                    q.push(ord[i]);
                }
            }

        }
        printf("%d\n",q.size());
        if (t)puts("");
    }
    return 0;
}
View Code

 

安装服务 LA 4850

标签:ring   opened   string   bsp   单位   none   工程   pop   tor   

原文地址:https://www.cnblogs.com/zhang2/p/11569164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!