File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed
solution/3500-3599/3500.Minimum Cost to Divide Array Into Subarrays Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ class Solution:
9898 n = len (nums)
9999 sumN = [0 ] * (n + 1 )
100100 sumC = [0 ] * (n + 1 )
101-
101+
102102 for i in range (1 , n + 1 ):
103103 sumN[i] = sumN[i - 1 ] + nums[i - 1 ]
104104 sumC[i] = sumC[i - 1 ] + cost[i - 1 ]
@@ -183,7 +183,7 @@ class Solution {
183183 if (start == n) return 0 ;
184184 return Long . MAX_VALUE ;
185185 }
186-
186+
187187 if (dp[start][end] != null ) return dp[start][end];
188188
189189 long currentNumsSum = prefixNums[end], currentCostSum = prefixCosts[n - 1 ];
@@ -212,14 +212,14 @@ class Solution {
212212 public:
213213 long long minimumCost(vector<int >& nums, vector<int >& cost, int K) {
214214 int n = nums.size();
215-
215+
216216 long long sn[n + 1], sc[n + 1];
217217 sn[0] = sc[0] = 0;
218218 for (int i = 1; i <= n; i++) {
219219 sn[i] = sn[i - 1] + nums[i - 1];
220220 sc[i] = sc[i - 1] + cost[i - 1];
221221 }
222-
222+
223223 const long long INF = 1e18 ;
224224 long long f[n + 1 ];
225225 for (int i = 0 ; i <= n; i++) f[i] = INF;
@@ -228,11 +228,11 @@ class Solution {
228228 long long t = sn[i] * (sc[i] - sc[j]) + K * (sc[n] - sc[j]);
229229 f[i] = min(f[i], f[j] + t);
230230 }
231-
231+
232232 return f[n];
233233 }
234234 };
235-
235+
236236```
237237
238238#### Go
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ class Solution:
9393 n = len (nums)
9494 sumN = [0 ] * (n + 1 )
9595 sumC = [0 ] * (n + 1 )
96-
96+
9797 for i in range (1 , n + 1 ):
9898 sumN[i] = sumN[i - 1 ] + nums[i - 1 ]
9999 sumC[i] = sumC[i - 1 ] + cost[i - 1 ]
@@ -178,7 +178,7 @@ class Solution {
178178 if (start == n) return 0 ;
179179 return Long . MAX_VALUE ;
180180 }
181-
181+
182182 if (dp[start][end] != null ) return dp[start][end];
183183
184184 long currentNumsSum = prefixNums[end], currentCostSum = prefixCosts[n - 1 ];
@@ -207,14 +207,14 @@ class Solution {
207207 public:
208208 long long minimumCost(vector<int >& nums, vector<int >& cost, int K) {
209209 int n = nums.size();
210-
210+
211211 long long sn[n + 1], sc[n + 1];
212212 sn[0] = sc[0] = 0;
213213 for (int i = 1; i <= n; i++) {
214214 sn[i] = sn[i - 1] + nums[i - 1];
215215 sc[i] = sc[i - 1] + cost[i - 1];
216216 }
217-
217+
218218 const long long INF = 1e18 ;
219219 long long f[n + 1 ];
220220 for (int i = 0 ; i <= n; i++) f[i] = INF;
@@ -223,7 +223,7 @@ class Solution {
223223 long long t = sn[i] * (sc[i] - sc[j]) + K * (sc[n] - sc[j]);
224224 f[i] = min(f[i], f[j] + t);
225225 }
226-
226+
227227 return f[n];
228228 }
229229 };
You can’t perform that action at this time.
0 commit comments