- 
 
- 
  Notifications
 You must be signed in to change notification settings 
- Fork 9.2k
feat: add new lc problems: No.2894~2897 #1764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
 
  Merged
 Changes from all commits
 Commits
 
 
 File filter
Filter by extension
Conversations
 Failed to load comments. 
 
 
 
  Loading
 
 Jump to
 
 Jump to file
 
 
 
 Failed to load files. 
 
 
 
  Loading
 
 Diff view
Diff view
There are no files selected for viewing
 
 
 
 103 changes: 103 additions & 0 deletions
 
 
 
 solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README.md
 
 
 
 
  
 
 
 
 
 
 
 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
 Learn more about bidirectional Unicode characters
 
 
 
 
 | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| # [2894. 分类求和并作差](https://leetcode.cn/problems/divisible-and-non-divisible-sums-difference) | ||
|  | ||
| [English Version](/solution/2800-2899/2894.Divisible%20and%20Non-divisible%20Sums%20Difference/README_EN.md) | ||
|  | ||
| ## 题目描述 | ||
|  | ||
| <!-- 这里写题目描述 --> | ||
|  | ||
| <p>给你两个正整数 <code>n</code> 和 <code>m</code> 。</p> | ||
|  | ||
| <p>现定义两个整数 <code>num1</code> 和 <code>num2</code> ,如下所示:</p> | ||
|  | ||
| <ul> | ||
| <li><code>num1</code>:范围 <code>[1, n]</code> 内所有 <strong>无法被 </strong><code>m</code><strong> 整除</strong> 的整数之和。</li> | ||
| <li><code>num2</code>:范围 <code>[1, n]</code> 内所有 <strong>能够被 </strong><code>m</code><strong> 整除</strong> 的整数之和。</li> | ||
| </ul> | ||
|  | ||
| <p>返回整数 <code>num1 - num2</code> 。</p> | ||
|  | ||
| <p> </p> | ||
|  | ||
| <p><strong class="example">示例 1:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>输入:</strong>n = 10, m = 3 | ||
| <strong>输出:</strong>19 | ||
| <strong>解释:</strong>在这个示例中: | ||
| - 范围 [1, 10] 内无法被 3 整除的整数为 [1,2,4,5,7,8,10] ,num1 = 这些整数之和 = 37 。 | ||
| - 范围 [1, 10] 内能够被 3 整除的整数为 [3,6,9] ,num2 = 这些整数之和 = 18 。 | ||
| 返回 37 - 18 = 19 作为答案。 | ||
| </pre> | ||
|  | ||
| <p><strong class="example">示例 2:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>输入:</strong>n = 5, m = 6 | ||
| <strong>输出:</strong>15 | ||
| <strong>解释:</strong>在这个示例中: | ||
| - 范围 [1, 5] 内无法被 6 整除的整数为 [1,2,3,4,5] ,num1 = 这些整数之和 = 15 。 | ||
| - 范围 [1, 5] 内能够被 6 整除的整数为 [] ,num2 = 这些整数之和 = 0 。 | ||
| 返回 15 - 0 = 15 作为答案。 | ||
| </pre> | ||
|  | ||
| <p><strong class="example">示例 3:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>输入:</strong>n = 5, m = 1 | ||
| <strong>输出:</strong>-15 | ||
| <strong>解释:</strong>在这个示例中: | ||
| - 范围 [1, 5] 内无法被 1 整除的整数为 [] ,num1 = 这些整数之和 = 0 。 | ||
| - 范围 [1, 5] 内能够被 1 整除的整数为 [1,2,3,4,5] ,num2 = 这些整数之和 = 15 。 | ||
| 返回 0 - 15 = -15 作为答案。 | ||
| </pre> | ||
|  | ||
| <p> </p> | ||
|  | ||
| <p><strong>提示:</strong></p> | ||
|  | ||
| <ul> | ||
| <li><code>1 <= n, m <= 1000</code></li> | ||
| </ul> | ||
|  | ||
| ## 解法 | ||
|  | ||
| <!-- 这里可写通用的实现逻辑 --> | ||
|  | ||
| <!-- tabs:start --> | ||
|  | ||
| ### **Python3** | ||
|  | ||
| <!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|  | ||
| ```python | ||
|  | ||
| ``` | ||
|  | ||
| ### **Java** | ||
|  | ||
| <!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|  | ||
| ```java | ||
|  | ||
| ``` | ||
|  | ||
| ### **C++** | ||
|  | ||
| ```cpp | ||
|  | ||
| ``` | ||
|  | ||
| ### **Go** | ||
|  | ||
| ```go | ||
|  | ||
| ``` | ||
|  | ||
| ### **...** | ||
|  | ||
| ``` | ||
|  | ||
| ``` | ||
|  | ||
| <!-- tabs:end --> | 
 
 
 
 93 changes: 93 additions & 0 deletions
 
 
 
 solution/2800-2899/2894.Divisible and Non-divisible Sums Difference/README_EN.md
 
 
 
 
  
 
 
 
 
 
 
 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
 Learn more about bidirectional Unicode characters
 
 
 
 
 | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # [2894. Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference) | ||
|  | ||
| [中文文档](/solution/2800-2899/2894.Divisible%20and%20Non-divisible%20Sums%20Difference/README.md) | ||
|  | ||
| ## Description | ||
|  | ||
| <p>You are given positive integers <code>n</code> and <code>m</code>.</p> | ||
|  | ||
| <p>Define two integers, <code>num1</code> and <code>num2</code>, as follows:</p> | ||
|  | ||
| <ul> | ||
| <li><code>num1</code>: The sum of all integers in the range <code>[1, n]</code> that are <strong>not divisible</strong> by <code>m</code>.</li> | ||
| <li><code>num2</code>: The sum of all integers in the range <code>[1, n]</code> that are <strong>divisible</strong> by <code>m</code>.</li> | ||
| </ul> | ||
|  | ||
| <p>Return <em>the integer</em> <code>num1 - num2</code>.</p> | ||
|  | ||
| <p> </p> | ||
| <p><strong class="example">Example 1:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>Input:</strong> n = 10, m = 3 | ||
| <strong>Output:</strong> 19 | ||
| <strong>Explanation:</strong> In the given example: | ||
| - Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37. | ||
| - Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18. | ||
| We return 37 - 18 = 19 as the answer. | ||
| </pre> | ||
|  | ||
| <p><strong class="example">Example 2:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>Input:</strong> n = 5, m = 6 | ||
| <strong>Output:</strong> 15 | ||
| <strong>Explanation:</strong> In the given example: | ||
| - Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15. | ||
| - Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0. | ||
| We return 15 - 0 = 15 as the answer. | ||
| </pre> | ||
|  | ||
| <p><strong class="example">Example 3:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>Input:</strong> n = 5, m = 1 | ||
| <strong>Output:</strong> -15 | ||
| <strong>Explanation:</strong> In the given example: | ||
| - Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0. | ||
| - Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15. | ||
| We return 0 - 15 = -15 as the answer. | ||
| </pre> | ||
|  | ||
| <p> </p> | ||
| <p><strong>Constraints:</strong></p> | ||
|  | ||
| <ul> | ||
| <li><code>1 <= n, m <= 1000</code></li> | ||
| </ul> | ||
|  | ||
| ## Solutions | ||
|  | ||
| <!-- tabs:start --> | ||
|  | ||
| ### **Python3** | ||
|  | ||
| ```python | ||
|  | ||
| ``` | ||
|  | ||
| ### **Java** | ||
|  | ||
| ```java | ||
|  | ||
| ``` | ||
|  | ||
| ### **C++** | ||
|  | ||
| ```cpp | ||
|  | ||
| ``` | ||
|  | ||
| ### **Go** | ||
|  | ||
| ```go | ||
|  | ||
| ``` | ||
|  | ||
| ### **...** | ||
|  | ||
| ``` | ||
|  | ||
| ``` | ||
|  | ||
| <!-- tabs:end --> | 
 
 
 
 92 changes: 92 additions & 0 deletions
 
 
 
 solution/2800-2899/2895.Minimum Processing Time/README.md
 
 
 
 
  
 
 
 
 
 
 
 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
 Learn more about bidirectional Unicode characters
 
 
 
 
 | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # [2895. 最小处理时间](https://leetcode.cn/problems/minimum-processing-time) | ||
|  | ||
| [English Version](/solution/2800-2899/2895.Minimum%20Processing%20Time/README_EN.md) | ||
|  | ||
| ## 题目描述 | ||
|  | ||
| <!-- 这里写题目描述 --> | ||
|  | ||
| <p>你有 <code>n</code> 颗处理器,每颗处理器都有 <code>4</code> 个核心。现有 <code>n * 4</code> 个待执行任务,每个核心只执行 <strong>一个</strong> 任务。</p> | ||
|  | ||
| <p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>processorTime</code> ,表示每颗处理器最早空闲时间。另给你一个下标从 <strong>0</strong> 开始的整数数组 <code>tasks</code> ,表示执行每个任务所需的时间。返回所有任务都执行完毕需要的 <strong>最小时间</strong> 。</p> | ||
|  | ||
| <p>注意:每个核心独立执行任务。</p> | ||
|  | ||
| <p> </p> | ||
|  | ||
| <p><strong>示例 1:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>输入:</strong>processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5] | ||
| <strong>输出:</strong>16 | ||
| <strong>解释:</strong> | ||
| 最优的方案是将下标为 4, 5, 6, 7 的任务分配给第一颗处理器(最早空闲时间 time = 8),下标为 0, 1, 2, 3 的任务分配给第二颗处理器(最早空闲时间 time = 10)。 | ||
| 第一颗处理器执行完所有任务需要花费的时间 = max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16 。 | ||
| 第二颗处理器执行完所有任务需要花费的时间 = max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13 。 | ||
| 因此,可以证明执行完所有任务需要花费的最小时间是 16 。</pre> | ||
|  | ||
| <p><strong>示例 2:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>输入:</strong>processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3] | ||
| <strong>输出:</strong>23 | ||
| <strong>解释:</strong> | ||
| 最优的方案是将下标为 1, 4, 5, 6 的任务分配给第一颗处理器(最早空闲时间 time = 10),下标为 0, 2, 3, 7 的任务分配给第二颗处理器(最早空闲时间 time = 20)。 | ||
| 第一颗处理器执行完所有任务需要花费的时间 = max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18 。 | ||
| 第二颗处理器执行完所有任务需要花费的时间 = max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23 。 | ||
| 因此,可以证明执行完所有任务需要花费的最小时间是 23 。 | ||
| </pre> | ||
|  | ||
| <p> </p> | ||
|  | ||
| <p><strong>提示:</strong></p> | ||
|  | ||
| <ul> | ||
| <li><code>1 <= n == processorTime.length <= 25000</code></li> | ||
| <li><code>1 <= tasks.length <= 10<sup>5</sup></code></li> | ||
| <li><code>0 <= processorTime[i] <= 10<sup>9</sup></code></li> | ||
| <li><code>1 <= tasks[i] <= 10<sup>9</sup></code></li> | ||
| <li><code>tasks.length == 4 * n</code></li> | ||
| </ul> | ||
|  | ||
| ## 解法 | ||
|  | ||
| <!-- 这里可写通用的实现逻辑 --> | ||
|  | ||
| <!-- tabs:start --> | ||
|  | ||
| ### **Python3** | ||
|  | ||
| <!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|  | ||
| ```python | ||
|  | ||
| ``` | ||
|  | ||
| ### **Java** | ||
|  | ||
| <!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|  | ||
| ```java | ||
|  | ||
| ``` | ||
|  | ||
| ### **C++** | ||
|  | ||
| ```cpp | ||
|  | ||
| ``` | ||
|  | ||
| ### **Go** | ||
|  | ||
| ```go | ||
|  | ||
| ``` | ||
|  | ||
| ### **...** | ||
|  | ||
| ``` | ||
|  | ||
| ``` | ||
|  | ||
| <!-- tabs:end --> | 
 
 
 
 82 changes: 82 additions & 0 deletions
 
 
 
 solution/2800-2899/2895.Minimum Processing Time/README_EN.md
 
 
 
 
  
 
 
 
 
 
 
 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
 Learn more about bidirectional Unicode characters
 
 
 
 
 | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # [2895. Minimum Processing Time](https://leetcode.com/problems/minimum-processing-time) | ||
|  | ||
| [中文文档](/solution/2800-2899/2895.Minimum%20Processing%20Time/README.md) | ||
|  | ||
| ## Description | ||
|  | ||
| <p>You have <code>n</code> processors each having <code>4</code> cores and <code>n * 4</code> tasks that need to be executed such that each core should perform only <strong>one</strong> task.</p> | ||
|  | ||
| <p>Given a <strong>0-indexed</strong> integer array <code>processorTime</code> representing the time at which each processor becomes available for the first time and a <strong>0-indexed </strong>integer array <code>tasks</code> representing the time it takes to execute each task, return <em>the <strong>minimum</strong> time when all of the tasks have been executed by the processors.</em></p> | ||
|  | ||
| <p><strong>Note: </strong>Each core executes the task independently of the others.</p> | ||
|  | ||
| <p> </p> | ||
| <p><strong class="example">Example 1:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>Input:</strong> processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5] | ||
| <strong>Output:</strong> 16 | ||
| <strong>Explanation:</strong> | ||
| It's optimal to assign the tasks at indexes 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indexes 0, 1, 2, 3 to the second processor which becomes available at time = 10. | ||
| Time taken by the first processor to finish execution of all tasks = max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16. | ||
| Time taken by the second processor to finish execution of all tasks = max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13. | ||
| Hence, it can be shown that the minimum time taken to execute all the tasks is 16.</pre> | ||
|  | ||
| <p><strong class="example">Example 2:</strong></p> | ||
|  | ||
| <pre> | ||
| <strong>Input:</strong> processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3] | ||
| <strong>Output:</strong> 23 | ||
| <strong>Explanation:</strong> | ||
| It's optimal to assign the tasks at indexes 1, 4, 5, 6 to the first processor which becomes available at time = 10, and the tasks at indexes 0, 2, 3, 7 to the second processor which becomes available at time = 20. | ||
| Time taken by the first processor to finish execution of all tasks = max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18. | ||
| Time taken by the second processor to finish execution of all tasks = max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23. | ||
| Hence, it can be shown that the minimum time taken to execute all the tasks is 23. | ||
| </pre> | ||
|  | ||
| <p> </p> | ||
| <p><strong>Constraints:</strong></p> | ||
|  | ||
| <ul> | ||
| <li><code>1 <= n == processorTime.length <= 25000</code></li> | ||
| <li><code>1 <= tasks.length <= 10<sup>5</sup></code></li> | ||
| <li><code>0 <= processorTime[i] <= 10<sup>9</sup></code></li> | ||
| <li><code>1 <= tasks[i] <= 10<sup>9</sup></code></li> | ||
| <li><code>tasks.length == 4 * n</code></li> | ||
| </ul> | ||
|  | ||
| ## Solutions | ||
|  | ||
| <!-- tabs:start --> | ||
|  | ||
| ### **Python3** | ||
|  | ||
| ```python | ||
|  | ||
| ``` | ||
|  | ||
| ### **Java** | ||
|  | ||
| ```java | ||
|  | ||
| ``` | ||
|  | ||
| ### **C++** | ||
|  | ||
| ```cpp | ||
|  | ||
| ``` | ||
|  | ||
| ### **Go** | ||
|  | ||
| ```go | ||
|  | ||
| ``` | ||
|  | ||
| ### **...** | ||
|  | ||
| ``` | ||
|  | ||
| ``` | ||
|  | ||
| <!-- tabs:end --> | 
 
 Oops, something went wrong.
 
 
 
 Add this suggestion to a batch that can be applied as a single commit.
 This suggestion is invalid because no changes were made to the code.
 Suggestions cannot be applied while the pull request is closed.
 Suggestions cannot be applied while viewing a subset of changes.
 Only one suggestion per line can be applied in a batch.
 Add this suggestion to a batch that can be applied as a single commit.
 Applying suggestions on deleted lines is not supported.
 You must change the existing code in this line in order to create a valid suggestion.
 Outdated suggestions cannot be applied.
 This suggestion has been applied or marked resolved.
 Suggestions cannot be applied from pending reviews.
 Suggestions cannot be applied on multi-line comments.
 Suggestions cannot be applied while the pull request is queued to merge.
 Suggestion cannot be applied right now. Please check back later.