-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from Kut-PS-Study/Dltmd202
Feat: Add solution of #118
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |