8980. 택배

멍진이·2021년 7월 7일
0

백준 문제풀기

목록 보기
31/36

문제 코드

city, size = list(map(int,input().split()))

city_box_list = [[0 for k in range(city)]for l in range(city)]

box_num = int(input())

for b in range(box_num):
    start, end, weight = list(map(int, input().split()))
    city_box_list[start-1][end-1] = weight

#print(city_box_list)

tmp_weight = size
count = 0

end_box_list = [0]*(city)

for i in range(city):
    count+=end_box_list[i]
    end_box_list[i]=0
    for j in range(i,city):
        if city_box_list[i][j] != 0 :
            can_weight = min(tmp_weight,city_box_list[i][j])

            end_box_list[j] += can_weight

            tmp_size = size
            for k in range(city):
                tmp_size-=end_box_list[k]
                if tmp_size<0:
                    end_box_list[k]+=tmp_size
                    for l in range(k+1,city):
                        end_box_list[l] =0
                    break


print(count)

문제 풀이

  • 마을에서 내릴 박스의 양을 들고다니는 배열 선언
  • 다음 마을에 갔을때 내릴께 있으면 내리고 count 증가
  • 더 실을께 있는데 size를 넘으면 마을이 가까운 것부터 실음
  • 이미 size를 초과했는데 마을이 더 가까운게 있으면 버리고 가까운거 실음
profile
개발하는 멍멍이

0개의 댓글