Skip to content

Commit

Permalink
Merge pull request #124 from Kut-PS-Study/Dltmd202
Browse files Browse the repository at this point in the history
Feat: Add solution of #118
  • Loading branch information
Dltmd202 authored Jul 8, 2022
2 parents bd58013 + ea55c79 commit 249a485
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/BaekJoon/Dltmd202/1654/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

public static void main(String[] args) throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine());
int k = Integer.parseInt(st.nextToken());
int n = Integer.parseInt(st.nextToken());
int[] cables = new int[k];
long left = 1L, right = 1L;

for (int i = 0; i < k; i++) {
cables[i] = Integer.parseInt(br.readLine());
right = Math.max(right, cables[i]);
}
right++;

System.out.println(getCableLength(n, cables, left, right));

}

private static long getCableLength(int n, int[] cables, long left, long right) {
int res = 0;
while (left < right){
long mid = (left + right) / 2;
int cutCnt = cut(cables, mid);

if(cutCnt < n){
right = mid;
} else {
left = mid + 1;
}
}
return left - 1;
}

public static int cut(int[] cables, long length){
int cnt = 0;
for (int cable : cables) {
cnt += (cable / length);
}
return cnt;
}
}

0 comments on commit 249a485

Please sign in to comment.