STUDY/Python 알고리즘
[백준] 2891번 카약과 강풍
Ojungii
2024. 5. 18. 22:55
이 문제는 그리디 문제입니다.
실버5 난이도여서 뚝딱하고 해결할줄 알았지만 예상외로 복잡한 코드로 풀었습니다.
접근법
- 리스트 생성
- 카약이 손상되었는데 여분 카약이 있는 팀을 우선적으로 제거
- 그 후 반복문 통해 앞뒤 팀의 여분 카약 여부 체크하고 있을 시 여분 카약 리스트(rev_r_teams)에서 제거
- 조건문에 걸리지 않으면 출발하지 못한 팀 cnt 증가
n,s,r = map(int,input().split())
teams = [i for i in range(1,n+1)]
s_teams = list(map(int,input().split()))
r_teams = list(map(int,input().split()))
cnt = 0
rev_s_teams = list(set(s_teams)-set(r_teams))
rev_r_teams = list(set(r_teams)-set(s_teams))
for i in teams:
if i in rev_s_teams :
if (i-1) in rev_r_teams:
rev_r_teams.pop(rev_r_teams.index(i-1))
continue
elif (i+1) in rev_r_teams:
rev_r_teams.pop(rev_r_teams.index(i+1))
continue
else :
cnt +=1
print(cnt)