Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- List 정렬
- 네트워크 용어
- c#
- List 제거
- 서브넷
- 서브넷 마스크
- 네트워크
- InsertRange
- IP주소
- AddRange
- Parse 사용법
- OSI 3계층
- C++
- 백준
- DP
- list
- List 추가
- Tostring 사용법
- list 사용법
- C# Contains
- 호스트
- C# Find
- 알고리즘
- c# list
- BFS
- Visual Studio
- 기본 게이트웨이
- TCP/IP
- List 찾기
- 호스트 주소
Archives
- Today
- Total
CodeLabs
[백준 / C#] 2805 : 나무 자르기 본문
using System;
namespace _2805
{
class Program
{
static long[] N_M, arr;
static long maxValue;
static bool Chack(long mid, long[] arr)
{
long cnt = 0;
for (long i = 0; i < N_M[0]; i++)
cnt += Math.Max(arr[i] - mid, 0);
return cnt >= N_M[1];
}
static void Solution(long[] arr, long wood)
{
long left = 1;
long result = 0;
while(left<=maxValue)
{
long mid = (left + maxValue) / 2;
if (Chack(mid, arr))
{
result = mid > result ? mid : result;
left = mid + 1;
}
else maxValue = mid - 1;
}
Console.WriteLine(result);
}
static void Input()
{
N_M = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
arr = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
Array.Sort(arr);
maxValue = arr[N_M[0] - 1];
}
static void Solve()
{
Input();
Solution(arr, N_M[1]);
}
static void Main(string[] args)
{
Solve();
}
}
}
'백준 > 1000 ~' 카테고리의 다른 글
[백준 / C#] 2667 : 단지번호붙이기 (0) | 2023.08.07 |
---|---|
[백준 / C#] 2630 : 색종이 만들기 (0) | 2023.08.04 |
[백준 / C#] 2606 : 바이러스 (0) | 2023.08.02 |
[백준 / C#] 2579 : 계단 오르기 (0) | 2023.07.30 |
[백준 / C#] 2178 : 미로탐색 (0) | 2023.07.28 |