일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 밴픽
- Substring with Concatenation of All Words
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- Convert Sorted List to Binary Search Tree
- 30. Substring with Concatenation of All Words
- concurrency
- 시바견
- DWG
- iterator
- 43. Multiply Strings
- shiba
- Regular Expression
- 프로그래머스
- t1
- Python
- LeetCode
- Protocol
- 컴퓨터의 구조
- Python Code
- data science
- kaggle
- 운영체제
- 315. Count of Smaller Numbers After Self
- attribute
- Decorator
- 파이썬
- Class
- Generator
- 715. Range Module
Archives
- Today
- Total
Scribbling
[C++] vector sum, vector max 본문
LeetCode: 410. Split Array Largest Sum
https://leetcode.com/problems/split-array-largest-sum/description/
class Solution {
public:
int splitArray(vector<int>& nums, int k) {
int ret = accumulate(nums.begin(), nums.end(), 0);
int left = *max_element(nums.begin(), nums.end());
int right(ret);
while (left <= right) {
int mid = (left + right) / 2;
int n = numGroups(nums, mid);
if (n <= k) {
ret = min(ret, mid);
right = mid - 1;
}
else {
left = mid + 1;
}
}
return ret;
}
int numGroups(vector<int>& nums, int limit) const {
int ret = 0;
int total = 0;
for (int num : nums) {
total += num;
if (total > limit) {
total = num;
ret++;
}
}
return ret + 1;
}
};
'Computer Science > C++' 카테고리의 다른 글
[C++] vector sum, dp table with vector (0) | 2023.09.02 |
---|---|
[C++] unordered_map, unordered_set, substr (0) | 2023.08.31 |
[C++] ostringstream, isdigit (0) | 2023.08.29 |
[C++] to_string, deque, string split (0) | 2023.08.24 |
[C++] istringstream (0) | 2023.08.22 |