-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJY_150369.java
More file actions
53 lines (45 loc) ยท 1.41 KB
/
JY_150369.java
File metadata and controls
53 lines (45 loc) ยท 1.41 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.*;
class JY_150369 {
public long solution(int cap, int n, int[] deliveries, int[] pickups) {
long answer = 0;
int i = n-1;
while(i >= 0) {
System.out.println("i: "+i);
System.out.println("d: "+Arrays.toString(deliveries));
System.out.println("p: "+Arrays.toString(pickups));
// ๋ฐฐ๋ฌ๊ณผ ์๊ฑฐ ๋ชจ๋ ๋๋ ์ง์ pass
if(deliveries[i] ==0 && pickups[i] ==0){
i--;
continue;
}
// ํ์ฌ ๊ฐ์ฅ ๋จผ ์ง์์น
int start = i+1;
// ๋ฐฐ๋ฌํ๊ธฐ
int capD = cap;
int d = i;
while(d >= 0) {
if(capD < deliveries[d]) {
deliveries[d] -= capD;
break;
}
capD -= deliveries[d];
deliveries[d] = 0;
d--;
}
// ์๊ฑฐํ๊ธฐ
int capP = cap;
int p = i;
while(p >= 0) {
if(capP < pickups[p]) {
pickups[p] -= capP;
break;
}
capP -= pickups[p];
pickups[p] = 0;
p--;
}
answer += (start*2);
}
return answer;
}
}