๐ฌย ๋ฌธ์
https://app.codility.com/programmers/lessons/16-greedy_algorithms/tie_ropes/
๐ฌย Idea
๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ์ฌ ๊ตฌ๊ฐํฉ์ ๊ตฌํ ๋ค ํฉ์ด K ์ด์์ด ๋๋ฉด ์นด์ดํธ๋ฅผ ์ฆ๊ฐ์ํจ๋ค. ๋ฐฐ์ด์ ๋๊น์ง ์ด๋ฅผ ๋ฐ๋ณตํ๋ค.
๐ฌย ํ์ด
publicfunc solution(_ K :Int, _ A :inout[Int])->Int{varsum=0varcnt=0foriin A {
sum += i
if sum >= K {
cnt +=1
sum =0}}return cnt
}์์์๊ฐ : 12๋ถ
์๊ฐ ๋ณต์ก๋ : O(N)
ํ๊ฐํ : https://app.codility.com/demo/results/training6874HK-B65/
๐ฌย ๋ฌธ์ https://app.codility.com/programmers/lessons/16-greedy_algorithms/tie_ropes/
๐ฌย Idea๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ์ฌ ๊ตฌ๊ฐํฉ์ ๊ตฌํ ๋ค ํฉ์ด K ์ด์์ด ๋๋ฉด ์นด์ดํธ๋ฅผ ์ฆ๊ฐ์ํจ๋ค. ๋ฐฐ์ด์ ๋๊น์ง ์ด๋ฅผ ๋ฐ๋ณตํ๋ค.
๐ฌย ํ์ด์์์๊ฐ: 12๋ถ์๊ฐ ๋ณต์ก๋: O(N)ํ๊ฐํ: https://app.codility.com/demo/results/training6874HK-B65/