Home (Python)[백준] 카약과 강풍
Post
Cancel

(Python)[백준] 카약과 강풍

2891번: 카약과 강풍

Solution


Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
n, s, r = map(int ,input().split())
broken = list(map(int, input().split()))
haveMore = list(map(int, input().split()))

boats = [1] * n

# 손상된 보트 -> 보유 보트수 -1
for i in broken:
    boats[i-1] -= 1

# 여분의 보트 -> 보유 보트수 +1
for i in haveMore:
    boats[i-1] += 1

for i in range(n):
    if boats[i] == 0: # 손상된 보트일 때(보트 보유수가 0)
        if i==0: # 첫 번째 순서
            if boats[i+1] == 2:
                boats[i+1] = 1
                boats[i] = 1

        elif i == n-1: # 마지막 순서
            if boats[i-1] == 2:
                boats[i-1] = 1
                boats[i] = 1

        else:
            if boats[i-1] == 2:
                boats[i-1] = 1
                boats[i] = 1
                continue              
            if boats[i+1] == 2:
                boats[i+1] = 1
                boats[i] = 1
                continue

    else: continue
    
print(boats.count(0))
This post is licensed under CC BY 4.0 by the author.