UVA,維吉尼亞大學

來源:互聯網
上載者:User

UVA,維吉尼亞大學

題目大意:有n個客戶,去買一家商場,結算時候排隊,每個顧客有一個等待時間,過了等待時間顧客就會不滿,然後每個顧客又有一個結算時間,問說最多讓幾個顧客滿意。

解題思路:先按照等待時間從小到大排列,然後遍曆一遍,每次加上當前人的時間,如果時間超過了當前的等待時間,則減掉前面滿意人當中結算時間最長的那個人的時間。

#include <cstdio>#include <queue>#include <algorithm>using namespace std;struct Order {    int q;    int d;    bool operator < (const Order& a) const {        return d < a.d;    }} A[800010];int main() {    int T;    scanf("%d", &T);    while (T--) {        int n;        scanf("%d", &n);        for (int i = 0; i < n; i++)            scanf("%d%d", &A[i].q, &A[i].d);        sort(A, A + n);        int cur = 0;        priority_queue<int> que;        for (int i = 0; i < n; i++) {            cur += A[i].q;            que.push(A[i].q);            if (cur > A[i].d) {                cur -= que.top();                que.pop();            }        }        printf("%ld\n", que.size());        if (T) puts("");    }    return 0;}

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.