๊ธ๊ณ ํธ์ด
์ด๋ ๊ฒ p๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌํด์ฃผ๊ณ !
import sys
read = sys.stdin.readline
W, N = map(int, read().split())
price = [list(map(int, read().split())) for _ in range(N)]
price.sort(key=lambda x:x[1], reverse=True)
total = 0
for m, p in price:
if W < m:
total += W * p
break
else:
total += m * p
W -= m
print(total)
8๋จ ๋ณ์๊ธฐ
import sys
read = sys.stdin.readline
num = list(map(int, read().split()))
num_list = [1, 2, 3, 4, 5, 6, 7, 8]
if num == num_list:
print("ascending")
elif num == sorted(num_list, reverse=True):
print("descending")
else:
print("mixed")
ใด ์ด๋ฐ ๊ฑธ ์๋ํ ๊ฒ ๋ง๋๊ฐ... ๋ด๋ ๋ชจ๋ฅด๊ฒ๋ค
์ฅ์ ๋ฌผ ์ธ์ ํ๋ก๊ทธ๋จ
import sys
from collections import deque
read = sys.stdin.readline
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
def out_of_range(y, x):
return y < 0 or x < 0 or y >= N or x >= N
def bfs(y, x):
que = deque()
que.append([y, x])
visited[y][x] = True
cnt = 1 # block์ด 1์ผ ๋๋ถํฐ ๋ค์ด์ค๊ธฐ ๋๋ฌธ์ 1๋ก ์ด๊ธฐํ
while que:
sy, sx = que.popleft()
for i in range(4):
ny = sy + dy[i]
nx = sx + dx[i]
if out_of_range(ny, nx) or visited[ny][nx] or block[ny][nx] != 1:
continue
else:
que.append([ny, nx])
visited[ny][nx] = True
cnt += 1
return cnt
N = int(read())
block = [list(map(int, input())) for _ in range(N)]
visited = [[False] * N for _ in range(N)]
result = []
for i in range(N):
for j in range(N):
if block[i][j] == 1 and not visited[i][j]:
result.append(bfs(i,j))
print(len(result))
result.sort()
for i in result:
print(i)
's t u d y . . ๐ง > coding test' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[softeer] level 1 !! ๐ฅ (0) | 2023.05.25 |
---|