일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 시바견
- Protocol
- data science
- 30. Substring with Concatenation of All Words
- 컴퓨터의 구조
- Python Code
- 315. Count of Smaller Numbers After Self
- t1
- kaggle
- 운영체제
- 밴픽
- Decorator
- shiba
- Regular Expression
- 43. Multiply Strings
- Class
- LeetCode
- Convert Sorted List to Binary Search Tree
- 715. Range Module
- Substring with Concatenation of All Words
- 109. Convert Sorted List to Binary Search Tree
- DWG
- concurrency
- attribute
- Python
- 프로그래머스
- Python Implementation
- iterator
- 파이썬
- Generator
Archives
- Today
- Total
Scribbling
[C++] Load Balancing 본문
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <queue>
#include <sstream>
#include <iostream>
#include <numeric>
using namespace std;
class Solution {
public:
int solution(int n, int m, vector<int>& burstTime) {
int ret = accumulate(burstTime.begin(), burstTime.end(), 0);
int left = *max_element(burstTime.begin(), burstTime.end());
int right = ret;
while (left <= right) {
int mid = (left + right) / 2;
int k = num_groups(burstTime, mid);
if (k <= n) {
ret = min(ret, mid);
right = mid - 1;
}
else {
left = mid + 1;
}
}
return ret;
}
int num_groups(vector<int>& burstTime, int limit) {
int cnt = 0;
int total = 0;
for (int t : burstTime) {
total += t;
if (total > limit) {
cnt++;
total = t;
}
}
return cnt + 1;
}
};
void main() {
int n = 3;
vector<int> vec1 = { 7, 2, 3, 4, 5 };
cout << Solution().solution(3, vec1.size(), vec1) << endl;
n = 2;
vector<int> vec2 = { 9, 2, 4, 4, 5};
cout << Solution().solution(2, vec2.size(), vec2) << endl;
}
'Computer Science > C++' 카테고리의 다른 글
[C++] istringstream (0) | 2023.08.22 |
---|---|
[C++] Chapter 2: Types (0) | 2023.08.21 |
[C++] lower_bound, upper_bound (0) | 2023.08.18 |
[C++] isalnum, tolower (0) | 2023.08.18 |
[C++] LeetCode 128. Longest Consecutive Sequence (0) | 2023.08.18 |