hrbust 2223水题 【优先队列】

水题
Time Limit: 500 MS Memory Limit: 32768 K
Total Submit: 407(138 users) Total Accepted: 153(99 users) Rating: Special Judge: No
Description

因为是有关于接水的问题,便简称为水题了(。

N个人排队在M个出水口前接水,第i个人接水需时为t[i]

请问接水的最短用时是多少?

Input

第一行一个整数 T ,代表有 T 组数据。

每组数据

第一行两个整数 N(<=100000) , M(<=10000) 代表有 N 个人 M 个出水口。

第二行N个整数,第i个数字t[i](<=10000)代表第i个人接水用时t[i]

Output
对于每组数据输出一个整数,代表所需的最少接水时间
Sample Input

2

5 3

1 2 3 4 5

6 3

1 2 3 3 4 5

Sample Output

5

6

Hint
小桥流水哗啦啦,我和小岛去偷瓜~
#include
using namespace std;
int a[100005];
bool cmp(int a, int b)
{
    return a > b;
}
int main()
{
    int N;
    cin >> N;
    while(N--)
    {
        int n, m;
        cin >> n >> m;
        priority_queue, greater >q;
        for(int i = 0; i < m; i++)
            q.push(0);
        for(int i = 0; i < n; i++)
            cin >> a[i];
        sort(a, a + n, cmp);
        for(int i = 0; i < n; i++)
        {
            int x = q.top();
            q.pop();
            x += a[i];
            q.push(x);
        }
        int ans = -1111;
        while(!q.empty())
        {
            if(ans < q.top())
                ans = q.top();
            q.pop();
        }
        cout << ans << endl;
    }
    return 0;
}

你可能感兴趣的:(STL)