Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add solution of #118 #124

Merged
merged 1 commit into from
Jul 8, 2022
Merged

Feat: Add solution of #118 #124

merged 1 commit into from
Jul 8, 2022

Conversation

Dltmd202
Copy link
Contributor

@Dltmd202 Dltmd202 commented Jul 6, 2022

#118 문제풀이

2022-07-06
@Dltmd202

문제

소스코드

\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;
    }
}

@Dltmd202 Dltmd202 merged commit 249a485 into master Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant