-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathYJ_150369.java
More file actions
25 lines (22 loc) ยท 932 Bytes
/
YJ_150369.java
File metadata and controls
25 lines (22 loc) ยท 932 Bytes
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
public class YJ_150369 {
public static void main(String[] args) {}
public long solution(int cap, int n, int[] deliveries, int[] pickups) {
int delivery = 0;
int pickup = 0;
long total = 0;
for(int i =n-1; i>=0; i--){
delivery += deliveries[i];
pickup += pickups[i];
//๋ฐฐ๋ฌ์ด๋ ์๊ฑฐํ ๊ฒ ์์ ๊ฒฝ์ฐ
while (delivery > 0 || pickup > 0){
//๋ฐฐ๋ฌ or ์๊ฑฐ๋ฅผ ๋ค ํ ๋ ๊น์ง ์ต๋ ์ฉ๋ cap ๋งํผ ๋ํ๊ธฐ
delivery -= cap;
pickup -= cap;
//์ด๋ ํ์ฌ ์์น๊น์ง ์๋ค๊ฐ๋ค๋ ๋ป์ผ๋ก ํ์ฌ์์น*2 ์๋ณต ๊ณ์ฐํ๊ธฐ
//์๋ค๊ฐ ์ด์ ๋ ํ๋ฒ ์ต๋์ฉ๋ ๋งํผ ์ถฉ์ ํ๋ฉด ์ดํ ๋จ์ ์ง๋ค๋ ๋ค๋ฆฌ๋ฉด์ ๋ฐฐ๋ฌ or ์๊ฑฐ๋ฅผ ํ๊ธฐ ๋๋ฌธ
total += (i+1)*2;
}
}
return total;
}
}