Skip to content

Commit e8c90c7

Browse files
committed
solve(programmers): LV3_금과_은_운반하기_kt
# id: 문제 id를 숫자로 작성 # categories : 해당 문제의 유형을 ,로 구분하여 작성 # tags : 해당 문제의 태그를 ,로 구분하여 작성 # time : 해당 문제 풀이에 걸린 시간을 분단위 숫자로 작성 # try : 해당 문제에 몇번의 시도를 했는지 숫자로 작성 # help: 해당 문제에 외부의 도움을 받았는지 true/false로 작성 # url : 해당 문제의 url을 작성 id: 86053 categories: [이진탐색] tags: [] time: 100 try: 2 help: true url: https://school.programmers.co.kr/learn/courses/30/lessons/86053
1 parent 94f4f3c commit e8c90c7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import kotlin.math.*
2+
3+
class Solution {
4+
fun solution(a: Int, b: Int, g: IntArray, s: IntArray, w: IntArray, t: IntArray): Long {
5+
var answer: Long = -1
6+
7+
val n=g.size
8+
9+
var low=0L
10+
11+
var high=((a+b)*2L*(t.maxOrNull()?:1).toLong())
12+
13+
while(low<high){
14+
val mid=low+(high-low)/2
15+
16+
var total=0L
17+
var mg=0L
18+
var ms=0L
19+
20+
for(i in 0 until n){
21+
val time=t[i]*2.toDouble()
22+
val count:Long=((mid+t[i])/time).toLong()
23+
val mines=count*w[i]
24+
mg+=min(g[i].toLong(),mines)
25+
ms+=min(s[i].toLong(),mines)
26+
total+=min(g[i].toLong()+s[i].toLong(),mines)
27+
}
28+
29+
if(total<a+b || mg<a || ms<b){
30+
low=mid+1
31+
}else{
32+
high=mid
33+
}
34+
}
35+
return high
36+
}
37+
}

0 commit comments

Comments
 (0)