Part3.7_이분탐색(결정알고리즘)&그리디 알고리즘_창고정리(그리디)

Eugenius1st·2022년 1월 13일
0

Python_algorithm

목록 보기
13/83

창고정리


가장 높은 곳에서 낮은 곳으로 m회 높이 조정한 후 차이 값 찾기

내가 생각한 코드

#1. Alt+W+N 입력하고 Alt+W+V :

import sys
sys.stdin = open("input.txt", "rt")
n= int(input())
a = list(map(int,input().split()))
m = int(input())

for i in range(m):
    a.sort()
    a[0] = a[0]+1
    a[n-1] = a[n-1]-1
a.sort()
print(a[n-1]-a[0])

100점 나왔다

뭔가 아쉬운 점?
배열 자체가 지저분 하다는거.. ㅎㅎ

#1. Alt+W+N 입력하고 Alt+W+V :

import sys
sys.stdin = open("input.txt", "rt")

L= int(input())
a = list(map(int,input().split()))
m = int(input())
a.sort()
for _ in range(m):
    a[0] += 1
    a[L-1] -= 1
    a.sort()
print(a[L-1]-a[0])

아휴우 참 깔끔하시네-
a[0]+= 1 하셨구나..

profile
최강 프론트엔드 개발자가 되고싶은 안유진 입니다

0개의 댓글