Skip to content

Commit a2da542

Browse files
committed
fix: cpp code
1 parent 3378247 commit a2da542

File tree

1 file changed

+11
-11
lines changed
  • solution/3000-3099/3086.Minimum Moves to Pick K Ones

1 file changed

+11
-11
lines changed

solution/3000-3099/3086.Minimum Moves to Pick K Ones/Solution.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@ class Solution {
44
int n = nums.size();
55
vector<int> cnt(n + 1, 0);
66
vector<long long> s(n + 1, 0);
7-
7+
88
for (int i = 1; i <= n; ++i) {
99
cnt[i] = cnt[i - 1] + nums[i - 1];
1010
s[i] = s[i - 1] + 1LL * i * nums[i - 1];
1111
}
12-
12+
1313
long long ans = LLONG_MAX;
14-
14+
1515
for (int i = 1; i <= n; ++i) {
1616
long long t = 0;
1717
int need = k - nums[i - 1];
18-
18+
1919
for (int j = i - 1; j <= i + 1; j += 2) {
2020
if (need > 0 && 1 <= j && j <= n && nums[j - 1] == 1) {
2121
--need;
2222
++t;
2323
}
2424
}
25-
25+
2626
int c = min(need, maxChanges);
2727
need -= c;
2828
t += c * 2;
29-
29+
3030
if (need <= 0) {
3131
ans = min(ans, t);
3232
continue;
3333
}
34-
34+
3535
int l = 2, r = max(i - 1, n - i);
36-
36+
3737
while (l <= r) {
3838
int mid = (l + r) / 2;
3939
int l1 = max(1, i - mid), r1 = max(0, i - 2);
4040
int l2 = min(n + 1, i + 2), r2 = min(n, i + mid);
41-
41+
4242
int c1 = cnt[r1] - cnt[l1 - 1];
4343
int c2 = cnt[r2] - cnt[l2 - 1];
44-
44+
4545
if (c1 + c2 >= need) {
4646
long long t1 = 1LL * c1 * i - (s[r1] - s[l1 - 1]);
4747
long long t2 = s[r2] - s[l2 - 1] - 1LL * c2 * i;
@@ -52,7 +52,7 @@ class Solution {
5252
}
5353
}
5454
}
55-
55+
5656
return ans;
5757
}
5858
};

0 commit comments

Comments
 (0)