[C++] 13335 : 트럭

리폐·2023년 11월 7일

백준

목록 보기
13/18
post-thumbnail

📝 문제

13335 : 트럭


✏️ 입력1

4 2 10
7 4 5 6

💻 출력1

8

✏️ 입력2

1 100 100
10

💻 출력2

101

✏️ 입력3

10 100 100
10 10 10 10 10 10 10 10 10 10

💻 출력3

110

⌨️ 소스코드

//13335 트럭
#include <iostream>
#include <queue>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	queue<int> que;
	int n, bridge_leng, Max_weight, cnt = 0;
	cin >> n >> bridge_leng >> Max_weight;

	int x[1000] = { 0, }, Sum_weight = 0;
	for(int i = 0; i < n; i++) cin >> x[i];

	for (int i = 0; i < n; i++) {
		while (1) {
			if (que.size() == bridge_leng) { //queue 사이즈가 다리 길이랑 같을때 
				Sum_weight -= que.front();
				que.pop();
			}
			if (x[i] + Sum_weight <= Max_weight) break; //최대 하중보다 작을때 while문 탈출 
			que.push(0);
			cnt++;
		}
		que.push(x[i]);
		Sum_weight += x[i];
		cnt++;
	}

	cout << cnt + bridge_leng;
}
profile
Unreal 5, Unity 공부

0개의 댓글