practivceAlgorithm/백준
[백준][Python] 1059 좋은구간
findTheValue
2021. 7. 30. 17:47
S의 요소인 좌우값 사이에 자리를 찾고 N의 왼쪽 오른쪽의 경우의수를 계산하는 문제이다.
import sys
input = sys.stdin.readline
from bisect import bisect
L = int(input())
AB_list = list(map(int,input().split()))
AB_list.sort()
N = int(input())
if N < AB_list[0]:
answer = max(0,(AB_list[0]-N)*(N)-1)
else:
index= bisect(AB_list,N)
answer = max(0,(AB_list[index]-N)*(N-AB_list[index-1])-1)
print(answer)