Skip to content

Commit 8258a74

Browse files
committed
Runtime: 0 ms (Top 100.00%) | Memory: 5.9 MB (Top 73.12%)
1 parent a7f901c commit 8258a74

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 0 ms (Top 100.00%) | Memory: 5.9 MB (Top 73.12%)
12
class Solution {
23
public:
34
int maxValue(int n, int index, int maxSum) {
@@ -9,21 +10,21 @@ class Solution {
910
int mid = lo + (hi- lo)/2;
1011
long sum = 0;
1112
long rs = 0, ls = 0, m = mid -1;
12-
if(r<=m)
13-
rs = m*(m+1)/2 - (m-r)*(m-r+1)/2; // if we have to calculate 9+8+7+6, sum = 9*(9+1)/2 - (9-4)(9-4+1)/2
14-
else
15-
rs = m*(m+1)/2 + r - m; // if we encounter the case in which array right to index is 3,2,1,1,1, sum = 3*(3+1)/2 + 5-2
16-
if(l<=m)
17-
ls = m*(m+1)/2 - (m-l)*(m-l+1)/2; // similar to above.
18-
else
19-
ls = m*(m+1)/2 + l-m;
20-
13+
if(r<=m)
14+
rs = m*(m+1)/2 - (m-r)*(m-r+1)/2; // if we have to calculate 9+8+7+6, sum = 9*(9+1)/2 - (9-4)(9-4+1)/2
15+
else
16+
rs = m*(m+1)/2 + r - m; // if we encounter the case in which array right to index is 3,2,1,1,1, sum = 3*(3+1)/2 + 5-2
17+
if(l<=m)
18+
ls = m*(m+1)/2 - (m-l)*(m-l+1)/2; // similar to above.
19+
else
20+
ls = m*(m+1)/2 + l-m;
21+
2122
sum = mid + ls + rs;
22-
23-
if(sum <= maxSum)
23+
24+
if(sum <= maxSum)
2425
res = mid,lo = mid+1;
2526
else hi = mid -1;
2627
}
2728
return res;
2829
}
29-
};
30+
};

0 commit comments

Comments
 (0)