-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueueImp.cpp
More file actions
41 lines (36 loc) · 736 Bytes
/
queueImp.cpp
File metadata and controls
41 lines (36 loc) · 736 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
41
#include <string>
#include <vector>
#include <queue>
using namespace std;
int solution(int bridge_length, int weight, vector<int> truck_weights) {
int answer = 0;
int idx=0;
int sum=0;
queue<int>q;
while(1)
{
if(idx==truck_weights.size())
{
answer += bridge_length;
break;
}
answer++;
int tmp = truck_weights[idx];
if(q.size()==bridge_length)
{
sum-=q.front();
q.pop();
}
if(sum+tmp<=weight)
{
sum += tmp;
q.push(tmp);
idx++;
}
else
{
q.push(0);
}
}
return answer;
}