-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_13335.cpp
More file actions
40 lines (32 loc) · 903 Bytes
/
BOJ_13335.cpp
File metadata and controls
40 lines (32 loc) · 903 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
int n, w, L;
int onBridge = 0;
int order = 0;
int answer = 0;
vector<int> truck;
queue<int> q;
int main() {
cin >> n >> w >> L;
for (int i = 0; i < n; i++) {
int input;
cin >> input;
truck.push_back(input);
}
for (int i = 0; i < n; i++) {
while (1) {
if (q.size() == w) { // 다리가 꽉 찬 경우
onBridge -= q.front(); // 맨 앞에 있는 트럭을 다리 밖으로 보내고,
q.pop(); // 다리 위 트럭 queue에서 제거
}
if (onBridge + truck.at(i) <= L) break; // 다리 위에 다음 트럭을 올릴 수 있는 경우에는 반복문을 빠져나가서 다리 위에 트럭 올리기
q.push(0); // 다리 위에 다음 트럭을 못 올리면 그 timing은 그냥 통과(무게가 0인 트럭)
answer++; // 시간 1 증가
}
q.push(truck.at(i)); // 다리 위에 트럭 올리기
onBridge += truck.at(i); // 다리 위의 트럭들 무게 계산
answer++; // 시간 1 증가
}
cout << answer + w;
return 0;
}