-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13335.cpp
More file actions
61 lines (59 loc) · 1.69 KB
/
13335.cpp
File metadata and controls
61 lines (59 loc) · 1.69 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
54
55
56
57
58
59
60
61
// 13335. 트럭
// 2020.05.27
// 시뮬레이션
#include<string>
#include<vector>
#include<queue>
#include<iostream>
using namespace std;
queue<int> q;
int main()
{
int n, w, L;
// n : 트럭의 수, w : 다리의 길이, L : 다리의 최대 하중
cin >> n >> w >> L;
vector<int> truck(n);
for (int i = 0; i < n; i++)
{
cin >> truck[i];
}
int bridge_weight = 0;
int time = 0;
for (int i = 0; i < truck.size(); i++)
{
while (1)
{
if (q.empty()) // 다리에 아무것도 없을때
{
q.push(truck[i]); // 다리에 현재 트럭 추가
time++; // 시간 추가
bridge_weight += truck[i]; // 총 무게 추가
break;
}
else if (q.size() == w) // 끝에 도달
{
bridge_weight -= q.front(); // 총 무게를 감소시켜줌
q.pop(); // 큐에서 트럭 제거
}
else
{
if (bridge_weight + truck[i] > L) // 대기중인 트럭까지 올라갔을때 트럭이 다리의 무게를 초과할 때
{
q.push(0); // 무게에 영향이 없는 0을 넣어줌
time++; // 시간 증가
}
else
{
// 큐가 비었을 때랑 동일
q.push(truck[i]);
time++;
bridge_weight += truck[i];
break;
}
}
}
}
// 총 시간 + 마지막 트럭 건너는 시간(다리의 길이)
cout << time + w << endl;
return 0;
}