Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Author : Saurav Kalsoor
- // Typing Speed
- import java.util.*;
- public class Test {
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- int n = sc.nextInt();
- int h = sc.nextInt();
- int[] words = new int[n];
- for(int i=0; i<n; i++){
- words[i] = sc.nextInt();
- }
- int result = typingSpeed(n, h, words);
- System.out.println(result);
- }
- public static int typingSpeed(int n, int h, int[] words){
- int low = 1, high = 1000000000, k = 1000000000;
- while(low <= high){
- int mid = low + (high - low) / 2;
- int requiredH = getH(n, mid, words);
- if(requiredH <= h){
- k = mid;
- high = mid-1;
- }else{
- low = mid+1;
- }
- }
- return k;
- }
- public static int getH(int n, int k, int[] words){
- int h = 0;
- for(int i=0; i < n; i++){
- h += Math.ceil(words[i]/(k*1.0));
- }
- return h;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement