The meaning of problems
http://acm.hdu.edu.cn/showproblem.php?pid=6709
Think
Consider all fish cooking time is less than k. After T descending order, which corresponds to cook a fish padded to time k.
Since fish cooking time will be greater than equal to k, then the optimal solution will not be enough to cook the fish situation occurs. During boiled fish, you can catch $ \ frac {t_i} {k} $ fish, the number of the last to be filled fish are n-cnt-1 strip. -1 did not start because most fish.
Code
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long int ll; 4 const int maxn=1E5+5; 5 int T; 6 ll n,k; 7 ll t[maxn]; 8 bool cmp(ll x,ll y) 9 { 10 return x>y; 11 } 12 void solve() 13 { 14 cin>>n>>k; 15 ll cnt=0,ans=0; 16 for(int i=1;i<=n;++i) 17 { 18 cin>>t[i]; 19 ans+=t[i]; 20 cnt+=t[i]/k; 21 t[i]%=k; 22 } 23 cnt=min(cnt,n); 24 sort(t+1,t+n+1,cmp); 25 for(int i=1;i<=n-cnt-1;++i) 26 ans+=k-t[i]; 27 cout<<ans+k<<endl; 28 } 29 int main() 30 { 31 ios::sync_with_stdio(false); 32 cin>>T; 33 while(T--) 34 solve(); 35 return 0; 36 }