二分基本题目
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstring> 5 #include <cmath> 6 #include <queue> 7 #include <stack> 8 #include <vector> 9 #include <set> 10 #include <map> 11 #include <sstream> 12 #include <algorithm> 13 using namespace std; 14 typedef long long ll; 15 const int maxn=2e4+9; 16 const ll mod=(ll)(1e9+7); 17 18 ll a[maxn],n,k; 19 bool judge(ll mid){///总时长 20 ll ans=0,num; 21 for(ll i=0;i<min(n,k);i++){ 22 num=mid/a[i];///在在该时长可以跑得趟数 23 if( num>=1 ){ 24 ans += (num-1)/2*4+5;///最后一趟过来送了5个人,其他的自己还在上面坐着,来回送4个人 25 } 26 else break; 27 } 28 if( ans>=n ) return 1; 29 return 0; 30 } 31 32 int main() 33 { 34 ll i,j,m,left,right,ans; 35 scanf("%lld %lld",&n,&k); 36 for(i=0;i<n;i++){ 37 scanf("%lld",&a[i]); 38 } 39 sort(a,a+n); 40 left=1; 41 right=2e10; 42 ans=2e11; 43 while( left<=right ){ 44 ll mid=(left+right)/2; 45 if( judge(mid) ){ 46 ans=min(ans,mid); 47 right=mid-1; 48 } 49 else left=mid+1; 50 } 51 printf("%lld ",ans); 52 return 0; 53 }