daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 랜선 자르기
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <limits.h>
  5.  
  6. int BSearch(int* ar, int f, int r, int target, int N)
  7. {
  8.     long long mid;
  9.     long long front = f;
  10.     long long rear = r;
  11.     int i;
  12.     int temp = 0;
  13.     int ans = 0;
  14.  
  15.     while(front<=rear)
  16.     {
  17.         mid = (front+rear)/2;
  18.         temp = 0;
  19.         for(i=0;i<N;i++)
  20.         {
  21.             temp += ar[i]/mid;
  22.         }
  23.         if(temp>=target)
  24.         {
  25.             front = mid+1;
  26.             ans = ans>mid?ans:mid;
  27.         }
  28.         else if(temp>target)
  29.         {
  30.             front = mid+1;
  31.         }
  32.         else
  33.         {
  34.             rear = mid-1;
  35.         }
  36.     }
  37.     return ans;
  38. }
  39. int main()
  40. {
  41.     int N, A;
  42.     int i;
  43.     int tmp = 0;
  44.     int arr[10000] = {0,};
  45.  
  46.     scanf("%d %d", &N, &A);
  47.     for(i=0;i<N;i++)
  48.     {
  49.         scanf("%d", &arr[i]);
  50.     }
  51.     tmp = BSearch(arr, 1, INT_MAX, A, N);
  52.     printf("%d", tmp);
  53.     return 0;
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top