We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 90b050c + 9ddc141 commit 6bd4f9dCopy full SHA for 6bd4f9d
3025. Find the Number of Ways to Place People I 2
@@ -0,0 +1,28 @@
1
+class Solution {
2
+public:
3
+ long long minOperations(vector<vector<int>>& queries) {
4
+ long long ans = 0;
5
+ for (auto &q : queries) {
6
+ int l = q[0], r = q[1];
7
+ long long S = 0;
8
+ int dMax = 0;
9
+
10
+ for (int k = 1; k <= 31; k++) {
11
+ long long low = 1LL << (k - 1);
12
+ long long high = (1LL << k) - 1;
13
+ if (low > r) break;
14
+ long long a = max((long long)l, low);
15
+ long long b = min((long long)r, high);
16
+ if (a > b) continue;
17
+ long long cnt = b - a + 1;
18
+ int stepsForK = (k + 1) / 2;
19
+ S += cnt * stepsForK;
20
+ dMax = max(dMax, stepsForK);
21
+ }
22
23
+ long long ops = max((long long)dMax, (S + 1) / 2);
24
+ ans += ops;
25
26
+ return ans;
27
28
+};
0 commit comments