목차

사격

ps
링크acmicpc.net/…
출처BOJ
문제 번호31264
문제명사격
레벨실버1
분류

파라메트릭 서치

시간복잡도O(nlogn + (m+n)logs)
인풋사이즈n<=10^5, m<=10^5, s<=10^5
사용한 언어Python 3.11
제출기록46184KB / 296ms
최고기록296ms
해결날짜2024/01/22

풀이

코드

"""Solution code for "BOJ 31264. 사격".

- Problem link: https://www.acmicpc.net/problem/31264
- Solution link: http://www.teferi.net/ps/problems/boj/31264

Tags: [binary search]
"""


import functools
from teflib import binsearch

INF = float('inf')


def is_valid(skill, m, s, a):
    tot_score = 0
    s_iter = iter(s)
    cur_score, next_score = 0, next(s_iter)
    for _ in range(m):
        while next_score <= skill:
            cur_score, next_score = next_score, next(s_iter, INF)
        tot_score += cur_score
        if tot_score >= a:
            return True
        skill += cur_score
    return False


def main():
    # pylint: disable=unused-variable
    N, M, A = [int(x) for x in input().split()]
    s = [int(x) for x in input().split()]

    s.sort()
    print(
        binsearch.minimum_valid_integer(
            s[0], s[-1] + 1, functools.partial(is_valid, m=M, s=s, a=A)
        )
    )


if __name__ == '__main__':
    main()