POJ(PKU)3104Drying

2017/12/05

もう解きたくない・
黒歴史ソース

#include <cstdio>
#include <algorithm>

using namespace std;

const int INF = 1000000002;

int n,k,d[100003];

bool ch( long long int x){
 
  
long long   int u = 0;
  
 for(int i = 0;i < n;i++){
   if(d[i] > x){
     u += (d[i] - x + k -2)/(k-1);
   }
 }
 
 return u <= x;
}

int main(){
  
  scanf("%d",&n);
  int mm = 0;
  for(int i = 0;i < n;i++){
    scanf("%d",&d[i]);
    mm = max(mm,d[i]);
  }
  
  scanf("%d",&k);
    int lb = -1,ub = INF;
  if(k == 1){
     ub = mm;
  }else{
  

  
  while(ub - lb > 1){
    int mid = (ub + lb) / 2;
    if(ch(mid)) ub = mid;
    else lb = mid;
  }
  
  }
  
  printf("%d
",ub);
  
  return 0;
  
}