diff --git a/solution/3100-3199/3152.Special Array II/README_EN.md b/solution/3100-3199/3152.Special Array II/README_EN.md
index 96f22fb8c1ff6..f01a74821d386 100644
--- a/solution/3100-3199/3152.Special Array II/README_EN.md
+++ b/solution/3100-3199/3152.Special Array II/README_EN.md
@@ -61,6 +61,10 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3152.Sp
+## Solutions
+
+
+
### Solution 1: Record the Leftmost Special Array Position for Each Position
We can define an array $d$ to record the leftmost special array position for each position, initially $d[i] = i$. Then we traverse the array $nums$ from left to right. If $nums[i]$ and $nums[i - 1]$ have different parities, then $d[i] = d[i - 1]$.
@@ -69,10 +73,6 @@ Finally, we traverse each query and check whether $d[to] <= from$ holds.
The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is the length of the array.
-
-
-### Solution 1
-
#### Python3
diff --git a/solution/3100-3199/3155.Maximum Number of Upgradable Servers/README.md b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/README.md
new file mode 100644
index 0000000000000..1109df6cae9a8
--- /dev/null
+++ b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/README.md
@@ -0,0 +1,158 @@
+---
+comments: true
+difficulty: 中等
+edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3155.Maximum%20Number%20of%20Upgradable%20Servers/README.md
+---
+
+
+
+# [3155. Maximum Number of Upgradable Servers 🔒](https://leetcode.cn/problems/maximum-number-of-upgradable-servers)
+
+[English Version](/solution/3100-3199/3155.Maximum%20Number%20of%20Upgradable%20Servers/README_EN.md)
+
+## 题目描述
+
+
+
+
You have n
data centers and need to upgrade their servers.
+
+You are given four arrays count
, upgrade
, sell
, and money
of length n
, which show:
+
+
+ - The number of servers
+ - The cost of upgrading a single server
+ - The money you get by selling a server
+ - The money you initially have
+
+
+for each data center respectively.
+
+Return an array answer
, where for each data center, the corresponding element in answer
represents the maximum number of servers that can be upgraded.
+
+Note that the money from one data center cannot be used for another data center.
+
+
+Example 1:
+
+
+
Input: count = [4,3], upgrade = [3,5], sell = [4,2], money = [8,9]
+
+
Output: [3,2]
+
+
Explanation:
+
+
For the first data center, if we sell one server, we'll have 8 + 4 = 12
units of money and we can upgrade the remaining 3 servers.
+
+
For the second data center, if we sell one server, we'll have 9 + 2 = 11
units of money and we can upgrade the remaining 2 servers.
+
+
+Example 2:
+
+
+
Input: count = [1], upgrade = [2], sell = [1], money = [1]
+
+
Output: [0]
+
+
+
+Constraints:
+
+
+ 1 <= count.length == upgrade.length == sell.length == money.length <= 105
+ 1 <= count[i], upgrade[i], sell[i], money[i] <= 105
+
+
+
+
+## 解法
+
+
+
+### 方法一:数学
+
+对于每个数据中心,我们假设可以升级 $\text{x}$ 台服务器,那么 $\text{x} \times \text{upgrade[i]} \leq \text{count[i]} \times \text{sell[i]} + \text{money[i]}$。即 $\text{x} \leq \frac{\text{count[i]} \times \text{sell[i]} + \text{money[i]}}{\text{upgrade[i]} + \text{sell[i]}}$。又因为 $\text{x} \leq \text{count[i]}$,所以我们取两者的最小值即可。
+
+时间复杂度 $O(n)$,其中 $n$ 为数组的长度。忽略答案数组的空间消耗,空间复杂度 $O(1)$。
+
+
+
+#### Python3
+
+```python
+class Solution:
+ def maxUpgrades(
+ self, count: List[int], upgrade: List[int], sell: List[int], money: List[int]
+ ) -> List[int]:
+ ans = []
+ for cnt, cost, income, cash in zip(count, upgrade, sell, money):
+ ans.append(min(cnt, (cnt * income + cash) // (cost + income)))
+ return ans
+```
+
+#### Java
+
+```java
+class Solution {
+ public int[] maxUpgrades(int[] count, int[] upgrade, int[] sell, int[] money) {
+ int n = count.length;
+ int[] ans = new int[n];
+ for (int i = 0; i < n; ++i) {
+ ans[i] = Math.min(
+ count[i], (int) ((1L * count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i])));
+ }
+ return ans;
+ }
+}
+```
+
+#### C++
+
+```cpp
+class Solution {
+public:
+ vector maxUpgrades(vector& count, vector& upgrade, vector& sell, vector& money) {
+ int n = count.size();
+ vector ans;
+ for (int i = 0; i < n; ++i) {
+ ans.push_back(min(count[i], (int) ((1LL * count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i]))));
+ }
+ return ans;
+ }
+};
+```
+
+#### Go
+
+```go
+func maxUpgrades(count []int, upgrade []int, sell []int, money []int) (ans []int) {
+ for i, cnt := range count {
+ ans = append(ans, min(cnt, (cnt*sell[i]+money[i])/(upgrade[i]+sell[i])))
+ }
+ return
+}
+```
+
+#### TypeScript
+
+```ts
+function maxUpgrades(
+ count: number[],
+ upgrade: number[],
+ sell: number[],
+ money: number[],
+): number[] {
+ const n = count.length;
+ const ans: number[] = [];
+ for (let i = 0; i < n; ++i) {
+ const x = ((count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i])) | 0;
+ ans.push(Math.min(x, count[i]));
+ }
+ return ans;
+}
+```
+
+
+
+
+
+
diff --git a/solution/3100-3199/3155.Maximum Number of Upgradable Servers/README_EN.md b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/README_EN.md
new file mode 100644
index 0000000000000..8673c75d55792
--- /dev/null
+++ b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/README_EN.md
@@ -0,0 +1,158 @@
+---
+comments: true
+difficulty: Medium
+edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3155.Maximum%20Number%20of%20Upgradable%20Servers/README_EN.md
+---
+
+
+
+# [3155. Maximum Number of Upgradable Servers 🔒](https://leetcode.com/problems/maximum-number-of-upgradable-servers)
+
+[中文文档](/solution/3100-3199/3155.Maximum%20Number%20of%20Upgradable%20Servers/README.md)
+
+## Description
+
+
+
+You have n
data centers and need to upgrade their servers.
+
+You are given four arrays count
, upgrade
, sell
, and money
of length n
, which show:
+
+
+ - The number of servers
+ - The cost of upgrading a single server
+ - The money you get by selling a server
+ - The money you initially have
+
+
+for each data center respectively.
+
+Return an array answer
, where for each data center, the corresponding element in answer
represents the maximum number of servers that can be upgraded.
+
+Note that the money from one data center cannot be used for another data center.
+
+
+Example 1:
+
+
+
Input: count = [4,3], upgrade = [3,5], sell = [4,2], money = [8,9]
+
+
Output: [3,2]
+
+
Explanation:
+
+
For the first data center, if we sell one server, we'll have 8 + 4 = 12
units of money and we can upgrade the remaining 3 servers.
+
+
For the second data center, if we sell one server, we'll have 9 + 2 = 11
units of money and we can upgrade the remaining 2 servers.
+
+
+Example 2:
+
+
+
Input: count = [1], upgrade = [2], sell = [1], money = [1]
+
+
Output: [0]
+
+
+
+Constraints:
+
+
+ 1 <= count.length == upgrade.length == sell.length == money.length <= 105
+ 1 <= count[i], upgrade[i], sell[i], money[i] <= 105
+
+
+
+
+## Solutions
+
+
+
+### Solution 1: Mathematics
+
+For each data center, we assume that we can upgrade $x$ servers, then $x \times \text{upgrade[i]} \leq \text{count[i]} \times \text{sell[i]} + \text{money[i]}$. That is, $x \leq \frac{\text{count[i]} \times \text{sell[i]} + \text{money[i]}}{\text{upgrade[i]} + \text{sell[i]}}$. Also, $x \leq \text{count[i]}$, so we can take the minimum of the two.
+
+The time complexity is $O(n)$, where $n$ is the length of the array. Ignoring the space consumption of the answer array, the space complexity is $O(1)$.
+
+
+
+#### Python3
+
+```python
+class Solution:
+ def maxUpgrades(
+ self, count: List[int], upgrade: List[int], sell: List[int], money: List[int]
+ ) -> List[int]:
+ ans = []
+ for cnt, cost, income, cash in zip(count, upgrade, sell, money):
+ ans.append(min(cnt, (cnt * income + cash) // (cost + income)))
+ return ans
+```
+
+#### Java
+
+```java
+class Solution {
+ public int[] maxUpgrades(int[] count, int[] upgrade, int[] sell, int[] money) {
+ int n = count.length;
+ int[] ans = new int[n];
+ for (int i = 0; i < n; ++i) {
+ ans[i] = Math.min(
+ count[i], (int) ((1L * count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i])));
+ }
+ return ans;
+ }
+}
+```
+
+#### C++
+
+```cpp
+class Solution {
+public:
+ vector maxUpgrades(vector& count, vector& upgrade, vector& sell, vector& money) {
+ int n = count.size();
+ vector ans;
+ for (int i = 0; i < n; ++i) {
+ ans.push_back(min(count[i], (int) ((1LL * count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i]))));
+ }
+ return ans;
+ }
+};
+```
+
+#### Go
+
+```go
+func maxUpgrades(count []int, upgrade []int, sell []int, money []int) (ans []int) {
+ for i, cnt := range count {
+ ans = append(ans, min(cnt, (cnt*sell[i]+money[i])/(upgrade[i]+sell[i])))
+ }
+ return
+}
+```
+
+#### TypeScript
+
+```ts
+function maxUpgrades(
+ count: number[],
+ upgrade: number[],
+ sell: number[],
+ money: number[],
+): number[] {
+ const n = count.length;
+ const ans: number[] = [];
+ for (let i = 0; i < n; ++i) {
+ const x = ((count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i])) | 0;
+ ans.push(Math.min(x, count[i]));
+ }
+ return ans;
+}
+```
+
+
+
+
+
+
diff --git a/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.cpp b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.cpp
new file mode 100644
index 0000000000000..c8b90c097709e
--- /dev/null
+++ b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.cpp
@@ -0,0 +1,11 @@
+class Solution {
+public:
+ vector maxUpgrades(vector& count, vector& upgrade, vector& sell, vector& money) {
+ int n = count.size();
+ vector ans;
+ for (int i = 0; i < n; ++i) {
+ ans.push_back(min(count[i], (int) ((1LL * count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i]))));
+ }
+ return ans;
+ }
+};
\ No newline at end of file
diff --git a/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.go b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.go
new file mode 100644
index 0000000000000..e0753de1010f1
--- /dev/null
+++ b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.go
@@ -0,0 +1,6 @@
+func maxUpgrades(count []int, upgrade []int, sell []int, money []int) (ans []int) {
+ for i, cnt := range count {
+ ans = append(ans, min(cnt, (cnt*sell[i]+money[i])/(upgrade[i]+sell[i])))
+ }
+ return
+}
\ No newline at end of file
diff --git a/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.java b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.java
new file mode 100644
index 0000000000000..28650a7422372
--- /dev/null
+++ b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.java
@@ -0,0 +1,11 @@
+class Solution {
+ public int[] maxUpgrades(int[] count, int[] upgrade, int[] sell, int[] money) {
+ int n = count.length;
+ int[] ans = new int[n];
+ for (int i = 0; i < n; ++i) {
+ ans[i] = Math.min(
+ count[i], (int) ((1L * count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i])));
+ }
+ return ans;
+ }
+}
\ No newline at end of file
diff --git a/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.py b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.py
new file mode 100644
index 0000000000000..4a16031fc0406
--- /dev/null
+++ b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.py
@@ -0,0 +1,8 @@
+class Solution:
+ def maxUpgrades(
+ self, count: List[int], upgrade: List[int], sell: List[int], money: List[int]
+ ) -> List[int]:
+ ans = []
+ for cnt, cost, income, cash in zip(count, upgrade, sell, money):
+ ans.append(min(cnt, (cnt * income + cash) // (cost + income)))
+ return ans
diff --git a/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.ts b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.ts
new file mode 100644
index 0000000000000..566f496fc1516
--- /dev/null
+++ b/solution/3100-3199/3155.Maximum Number of Upgradable Servers/Solution.ts
@@ -0,0 +1,14 @@
+function maxUpgrades(
+ count: number[],
+ upgrade: number[],
+ sell: number[],
+ money: number[],
+): number[] {
+ const n = count.length;
+ const ans: number[] = [];
+ for (let i = 0; i < n; ++i) {
+ const x = ((count[i] * sell[i] + money[i]) / (upgrade[i] + sell[i])) | 0;
+ ans.push(Math.min(x, count[i]));
+ }
+ return ans;
+}
diff --git a/solution/README.md b/solution/README.md
index 4d5022069bf07..86297bb930075 100644
--- a/solution/README.md
+++ b/solution/README.md
@@ -3165,6 +3165,7 @@
| 3152 | [特殊数组 II](/solution/3100-3199/3152.Special%20Array%20II/README.md) | | 中等 | 第 398 场周赛 |
| 3153 | [所有数对中数位不同之和](/solution/3100-3199/3153.Sum%20of%20Digit%20Differences%20of%20All%20Pairs/README.md) | | 中等 | 第 398 场周赛 |
| 3154 | [到达第 K 级台阶的方案数](/solution/3100-3199/3154.Find%20Number%20of%20Ways%20to%20Reach%20the%20K-th%20Stair/README.md) | | 困难 | 第 398 场周赛 |
+| 3155 | [Maximum Number of Upgradable Servers](/solution/3100-3199/3155.Maximum%20Number%20of%20Upgradable%20Servers/README.md) | | 中等 | 🔒 |
## 版权
diff --git a/solution/README_EN.md b/solution/README_EN.md
index 5368441dc3d71..b9f7cf205c6e6 100644
--- a/solution/README_EN.md
+++ b/solution/README_EN.md
@@ -3163,6 +3163,7 @@ Press Control + F(or Command + F on
| 3152 | [Special Array II](/solution/3100-3199/3152.Special%20Array%20II/README_EN.md) | | Medium | Weekly Contest 398 |
| 3153 | [Sum of Digit Differences of All Pairs](/solution/3100-3199/3153.Sum%20of%20Digit%20Differences%20of%20All%20Pairs/README_EN.md) | | Medium | Weekly Contest 398 |
| 3154 | [Find Number of Ways to Reach the K-th Stair](/solution/3100-3199/3154.Find%20Number%20of%20Ways%20to%20Reach%20the%20K-th%20Stair/README_EN.md) | | Hard | Weekly Contest 398 |
+| 3155 | [Maximum Number of Upgradable Servers](/solution/3100-3199/3155.Maximum%20Number%20of%20Upgradable%20Servers/README_EN.md) | | Medium | 🔒 |
## Copyright