LittleWho

Untitled

Apr 17th, 2021
870
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2. v = list(map(int, input().split(' ')))
  3. v = sorted(v)
  4.  
  5. from sys import setrecursionlimit
  6. setrecursionlimit(10000)
  7.  
  8. mem = [[-1 for _ in range(n)] for _ in range(n)]
  9. def dp(l, r):
  10.     if l==r: return 0
  11.     if mem[l][r] != -1: return mem[l][r]
  12.     mem[l][r] = v[r] - v[l] + min(dp(l+1, r), dp(l, r-1))
  13.     return mem[l][r]
  14.  
  15. print (dp(0, len(v)-1))
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×