using System;
public class Solution {
public int solution(int n, int m, int[] section) {
int answer = 0;
int[] paint = new int[n];
for (int i = 0; i < n; ++i)
{
paint[i] = 1;
}
for (int i = 0; i < section.Length; ++i)
{
paint[section[i] - 1] = 0;
}
for(int i = 0; i < paint.Length; ++i)
{
if(paint[i] == 0)
{
for (int j = 0; j < m; ++j)
{
int arrayLength = i + j;
if (arrayLength > paint.Length - 1) arrayLength = paint.Length - 1;
paint[arrayLength] = 1;
}
answer++;
}
}
return answer;
}
}
'C# 알고리즘 코드카타' 카테고리의 다른 글
61. 로또의 최고 순위와 최저 순위 (0) | 2023.12.19 |
---|---|
60. 기사단원의 무기 (1) | 2023.12.18 |
58. 소수 만들기 (0) | 2023.12.14 |
57. 모의고사 (0) | 2023.12.13 |
56. 과일 장수 (0) | 2023.12.12 |