1191 python
\tclass Solution:\n\t\tdef kConcatenationMaxSum(self, arr: List[int], k: int) -> int:\n\t\t\tn = len(arr)\n\t\t\tdp = [0]n\n\t\t\tmod = int(1e9+7)\n\n\t\t\tdp[0
\tclass Solution:\n\t\tdef kConcatenationMaxSum(self, arr: List[int], k: int) -> int:\n\t\t\tn = len(arr)\n\t\t\tdp = [0]*n\n\t\t\tmod = int(1e9+7)\n\n\t\t\tdp[0] = arr[0]\n\t\t\ttotal = arr[0]\n\t\t\tidxzero = arr[0]\n\n\t\t\tfor i in range(1,n):\n\t\t\t\tdp[i] = max(dp[i-1]+arr[i],arr[i])\n\t\t\t\ttotal += arr[i]\n\t\t\t\tidxzero = max(idxzero,total)\n\n\n\t\t\tidxlast = dp[-1]\n\t\t\tisolated = max(dp+[0])\n\n\t\t\tif k == 1:\n\t\t\t\treturn isolated%mod\n\n\t\t\treturn max(isolated,idxzero+idxlast+max(0,(k-2)*total))%mod
['Dynamic Programming', 'Python']