부분합 최대 부분합은 이해하는 상태에서 풀면 그나마 손 쉽다
 
 
n=int(input())
do_p, to_p=map(int,input().split())
do_k=int(input())
arr_k=[0]*(n+1)
for i in range(n):
  arr_k[i]=int(input())
 
arr_k.sort(reverse=True)
#print(arr_k)
 
res=0
res1=0
 
def partial_sum(arr, a, b):
  arr = [0] + arr
  partial_sum = [0] * len(arr)
 
  for i in range(1, len(arr)):
    partial_sum[i] = partial_sum[i-1] + arr[i]
 
  partial_sum = partial_sum[1:]
#  print("partial_sum", partial_sum)
    
#  print("total sum", partial_sum[-1])
  
  if((a-1)<0):
    return partial_sum[b]
  else:
    return partial_sum[b] - partial_sum[a-1]
 
#print("aaaa=",partial_sum(arr_k, 0, 1))
 
 
for i in range(n):
  res1=(do_k+partial_sum(arr_k, 0, i))//(do_p+(to_p*(i+1)))
 
  if res < res1:
    res=res1
  elif res > res1:
    break
 
  
print(res)

+ Recent posts