-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13335_ํธ๋ญ.java
More file actions
44 lines (42 loc) ยท 1.65 KB
/
13335_ํธ๋ญ.java
File metadata and controls
44 lines (42 loc) ยท 1.65 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int N, W, L, cnt, nowWeight;
static int[] arr, bridge;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
W = Integer.parseInt(st.nextToken());
L = Integer.parseInt(st.nextToken());
arr = new int[N];
bridge = new int[W];
st = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int idx = 0;
while (true) {
cnt++; //์๊ฐ์ฆ๊ฐ
if(bridge[0] != 0) { //๋ค๋ฆฌ์ ๋งจ ์์ ํธ๋ญ์ด ์๋ค๋ฉด ์ ๊ฑฐ ํ ๋น์ฐ๊ธฐ
nowWeight -= bridge[0];
bridge[0] = 0;
}
for(int i=1; i<bridge.length; i++) { //๋ค๋ฆฌ์์ ํธ๋ญ์ด ํ์นธ์ฉ ๊ฑด๋๋ ๋ก์ง
bridge[i - 1] = bridge[i];
bridge[i] = 0;
}
if((nowWeight+arr[idx]) <= L) { //ํ์ค๋ณด๋ค ๋ฎ์ ๊ฒฝ์ฐ์๋ง
bridge[bridge.length-1] = arr[idx++]; //๋ค๋ฆฌ๋ฅผ ํ๊ณ
nowWeight += arr[idx-1]; //ํ์ค ์ฆ๊ฐ
if(idx == arr.length) { //๋ค๋ฆฌ๋ฅผ ๋ค ์ฌ๋ผํ์ ๊ฒฝ์ฐ
cnt += W; //๋ง์ง๋ง ํธ๋ญ์ด ๊ฑด๋๋ ์๊ฐ ์ถ๊ฐ ํ
break; //์ข
๋ฃ
}
}
}
System.out.println(cnt);
}
}