| 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()