forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cs solution to lc problem: No.2834 (doocs#2415)
No.2834.Find the Minimum Possible Sum of a Beautiful Array
- Loading branch information
Showing
3 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
12 changes: 12 additions & 0 deletions
12
solution/2800-2899/2834.Find the Minimum Possible Sum of a Beautiful Array/Solution.cs
This file contains 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,12 @@ | ||
public class Solution { | ||
public int MinimumPossibleSum(int n, int target) { | ||
const int mod = (int) 1e9 + 7; | ||
int m = target / 2; | ||
if (n <= m) { | ||
return (int) ((1L + n) * n / 2 % mod); | ||
} | ||
long a = (1L + m) * m / 2 % mod; | ||
long b = ((1L * target + target + n - m - 1) * (n - m) / 2) % mod; | ||
return (int) ((a + b) % mod); | ||
} | ||
} |