天天看點

Accelerator pku 3232

Accelerator

Time Limit:4000MS  Memory Limit:65536K

Total Submit:2011 Accepted:428

Description

Input

Output

For each of test cases print a single integer on a single line, the minimal possible number of time units required to finish the race all team.

Sample Input

Sample Output

Source

South Central China 2007 hosted by NUDT

Accelerator pku 3232

#include  < iostream >

Accelerator pku 3232

#include  < cstdio >

Accelerator pku 3232

using   namespace  std;

Accelerator pku 3232
Accelerator pku 3232

int  riders[ 100005 ];

Accelerator pku 3232

int  n,t,m,k;

Accelerator pku 3232

bool  IsOk( int  times)

Accelerator pku 3232
Accelerator pku 3232

... {

Accelerator pku 3232

    long long need=0,i;

Accelerator pku 3232

    int flag;

Accelerator pku 3232

    for(i=0;i<n;i++)

Accelerator pku 3232
Accelerator pku 3232

   ...{  

Accelerator pku 3232

     flag=(riders[i]-times+k-2)/(k-1);

Accelerator pku 3232

     if(flag>0)

Accelerator pku 3232

       need+=flag;

Accelerator pku 3232

     if(flag>times)

Accelerator pku 3232

         return false;

Accelerator pku 3232

   }

Accelerator pku 3232

    if(need<=(long long)m*times)

Accelerator pku 3232

       return true;

Accelerator pku 3232

    else return false;

Accelerator pku 3232

}

Accelerator pku 3232

void  Init()

Accelerator pku 3232
Accelerator pku 3232

... {

Accelerator pku 3232

    int i;

Accelerator pku 3232

    scanf("%d",&n);

Accelerator pku 3232

    for(i=0;i<n;i++)

Accelerator pku 3232

     scanf("%d",&riders[i]);

Accelerator pku 3232

    scanf("%d%d",&m,&k);    

Accelerator pku 3232

}

Accelerator pku 3232

int  main()

Accelerator pku 3232
Accelerator pku 3232

... {

Accelerator pku 3232

    cin>>t;

Accelerator pku 3232

    while(t--)

Accelerator pku 3232
Accelerator pku 3232

    ...{

Accelerator pku 3232

     Init();  

Accelerator pku 3232

     if(k==1)

Accelerator pku 3232
Accelerator pku 3232

       ...{

Accelerator pku 3232

            int tmp=-1;

Accelerator pku 3232

            for(int i=0;i<n;i++)

Accelerator pku 3232

             if(riders[i]>tmp)

Accelerator pku 3232

              tmp=riders[i];

Accelerator pku 3232

             cout<<tmp<<endl; 

Accelerator pku 3232

         continue;    

Accelerator pku 3232

        }

Accelerator pku 3232

     int min=0,max=100000000,mid;  

Accelerator pku 3232

        while(min<max)

Accelerator pku 3232
Accelerator pku 3232

        ...{

Accelerator pku 3232

              mid=(min+max)/2;

Accelerator pku 3232

              if(IsOk(mid))

Accelerator pku 3232

                 max=mid;

Accelerator pku 3232

              else 

Accelerator pku 3232

                  min=mid+1;

Accelerator pku 3232

        }

Accelerator pku 3232

      cout<<min<<endl; 

Accelerator pku 3232

    }

Accelerator pku 3232

  return 0;

Accelerator pku 3232

}

Accelerator pku 3232
Accelerator pku 3232
3
2      
2
3
2 3 9
1 5
3
2 3 6
1 5
      

The input file has T (1<T<20) test cases, and the first line of the file will show the T.

Each of test cases, will be the N (1<= N <= 100000) rider, and N numbers Ai (1<= Ai <= 10^8) show how long will the rider have to finish the race. And the M and the K (1<= K*M <=10^8) for the accelerators.

Shiming (alpc02) is a boy likes to play PopKart very much. He is a good rider in this game. And one day he thought that he became a team leader of a team of N Kart riders.

Today, after the game begins, the riders of his team are now at different places at the racetrack, for that some of the riders got some short cut.

Accelerator pku 3232

However, we know actually how long has each rider left to run along, and they will ride actually one meter per one time unit (maybe 10ms).

Luckily, Shiming now gets M accelerators, the accelerator can help one rider to ride k meters per one time unit. And all the accelerators are as the same. But one rider can't use more than one accelerator at one time unit.

Shiming is the team leader, and he wants all the team members to finish in the minimal time not just the fastest one to finish the race. He will distribute all the accelerators to the riders.

Note: Here some rules are not as the same as the game we played. At a time unit, Shiming distributes the accelerators to riders for one rider one accelerator, and at the next time unit, all the accelerator can be reused, and Shiming can re-distributes all the accelerators to riders also for one rider one accelerator and the distribution is no relationship with the last time unit.

So you will program to help Shiming to get the actually minimal time the team will use to finish the race.

繼續閱讀