ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Fishing Master(2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛)

2019-08-26 23:04:24  阅读:571  来源: 互联网

标签:q1 mins fish CCPC 2019 time catch Master include


Problem Description Heard that eom is a fishing MASTER, you want to acknowledge him as your mentor. As everybody knows, if you want to be a MASTER's apprentice, you should pass the trial. So when you find fishing MASTER eom, the trial is as follow:

There are n fish in the pool. For the i - th fish, it takes at least ti minutes to stew(overcook is acceptable). To simplify this problem, the time spent catching a fish is kminutes. You can catch fish one at a time and because there is only one pot, only one fish can be stewed in the pot at a time. While you are catching a fish, you can not put a raw fish you have caught into the pot, that means if you begin to catch a fish, you can't stop until after k minutes; when you are not catching fish, you can take a cooked fish (stewed for no less than ti) out of the pot or put a raw fish into the pot, these two operations take no time. Note that if the fish stewed in the pot is not stewed for enough time, you cannot take it out, but you can go to catch another fish or just wait for a while doing nothing until it is sufficiently stewed.

Now eom wants you to catch and stew all the fish as soon as possible (you definitely know that a fish can be eaten only after sufficiently stewed), so that he can have a satisfying meal. If you can complete that in the shortest possible time, eom will accept you as his apprentice and say "I am done! I am full!". If you can't, eom will not accept you and say "You are done! You are fool!".

So what's the shortest time to pass the trial if you arrange the time optimally?  

 

Input The first line of input consists of a single integer T(1≤T≤20), denoting the number of test cases.

For each test case, the first line contains two integers n(1≤n≤105),k(1≤k≤109), denoting the number of fish in the pool and the time needed to catch a fish.

the second line contains n integers, t1,t2,…,tn(1≤ti≤109) ,denoting the least time needed to cook the i - th fish.  

 

Output For each test case, print a single integer in one line, denoting the shortest time to pass the trial.  

 

Sample Input 2 3 5 5 5 8 2 4 3 3  

 

Sample Output 23 11 Hint Case 1: Catch the 3rd fish (5 mins), put the 3rd fish in, catch the 1st fish (5 mins), wait (3 mins), take the 3rd fish out, put the 1st fish in, catch the 2nd fish(5 mins), take the 1st fish out, put the 2nd fish in, wait (5 mins), take the 2nd fish out. Case 2: Catch the 1st fish (4 mins), put the 1st fish in, catch the 2nd fish (4 mins), take the 1st fish out, put the 2nd fish in, wait (3 mins), take the 2nd fish out.    
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
typedef long long ll;
using namespace std;
const int INT=1e6+5;
#define lson rt<<1, l, m  
#define rson rt<<1|1, m+1, r
#define read(x) scanf("%d",&x)
#define lread(x) scanf("%lld",&x);
#define pt(x) printf("%d\n",(x))
#define cn cin>>
#define ct cout<<
#define en <<endl
#define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
#define mem(s,t) memset(s,t,sizeof(s))
#define re return 0;
ll a[100000+5],b[10000+5];
priority_queue<ll>q1,q2;
int main()
{
    ll t,n,k,m;
    //cn t;
    read(t);
    while(t--)
    {
        //cn n>>k;
        scanf("%lld %lld",&n,&k);
        rep(1,n) lread(a[i]);//cn a[i];
        sort(a+1,a+1+n);

        for(int i=n;i>=1;i--)
        {
            if(!q1.empty())
            {
                int x=q1.top();
                q1.pop();
                if(x>k)
                    q1.push( x-k );
            }
            q1.push(a[i]);
        }
        ll sum=n*k;
        while(!q1.empty())
        {
            sum+=q1.top(); q1.pop();
        }
        printf("%lld\n",sum);
        //ct sum en;
        
    }
    re
}

 

标签:q1,mins,fish,CCPC,2019,time,catch,Master,include
来源: https://www.cnblogs.com/Shallow-dream/p/11415578.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有