Skip to content

Commit

Permalink
63-9kyo-hwang
Browse files Browse the repository at this point in the history
  • Loading branch information
9kyo-hwang committed Sep 3, 2024
1 parent f754cc5 commit abe7706
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
cin.tie(nullptr)->sync_with_stdio(false);

int N, M; cin >> N >> M;

vector<int> Nums(N);
for(int& Num : Nums)
{
cin >> Num;
}

auto IsValid = [&](int EstimateScore)
{
int Count = 1;
int Min = Nums[0], Max = Nums[0];

for(int i = 1; i < N; ++i)
{
Min = min(Min, Nums[i]);
Max = max(Max, Nums[i]);

if(Max - Min > EstimateScore)
{
Count++;
Min = Nums[i];
Max = Nums[i];
}
}

return Count <= M;
};

int Min = 0, Max = *max_element(Nums.begin(), Nums.end());
int Score = Max;
while(Min <= Max)
{
int EstimateScore = (Min + Max) / 2;
if(IsValid(EstimateScore))
{
Score = min(Score, EstimateScore);
Max = EstimateScore - 1;
}
else
{
Min = EstimateScore + 1;
}
}

cout << Score;

return 0;
}
3 changes: 2 additions & 1 deletion 9-kyo-hwang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@
| 59์ฐจ์‹œ | 2024.8.01 | Greedy | [๋งˆ๋ฒ•์˜ ์—˜๋ฆฌ๋ฒ ์ดํ„ฐ](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) |
| 60์ฐจ์‹œ | 2024.8.05 | Implementation | [๊ณผ์ œ ์ง„ํ–‰ํ•˜๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/176962) | [#213](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/213) |
| 61์ฐจ์‹œ | 2024.8.08 | Implementation | [ํ…Œ์ด๋ธ” ํ•ด์‹œ ํ•จ์ˆ˜](https://school.programmers.co.kr/learn/courses/30/lessons/147354) | [#214](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/214) |
| 62์ฐจ์‹œ | 2024.8.12 | Graph Traversal | [๋ฌด์ธ๋„ ์—ฌํ–‰](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#217](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/217) |
| 62์ฐจ์‹œ | 2024.8.12 | Graph Traversal | [๋ฌด์ธ๋„ ์—ฌํ–‰](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#217](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/217) |
| 63์ฐจ์‹œ | 2024.9.3 | Binary Search | [๊ตฌ๊ฐ„ ๋‚˜๋ˆ„๊ธฐ2](https://www.acmicpc.net/problem/13397) | [#218](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/218) |

0 comments on commit abe7706

Please sign in to comment.