트럭 주차(x)

한경식·2024년 12월 17일

https://www.acmicpc.net/problem/2979

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int a, b, c;
int arr[101];
int n, m;
int sum;
int main()
{
	cin >> a >> b >> c;
	for (int i = 0; i < 3; i++)
	{
		cin >> n >> m;

		for (int j = n; j < m; j++)
		{
			arr[j]++;
		}
	}

	for (int i = 0; i < 100; i++)
	{
		if (arr[i] == 1)
			sum += a;
		else if (arr[i] == 2)
			sum += b*2;
		else if (arr[i] == 3)
			sum += c*3;
	}

	cout << sum << endl;
}
  • 시작 시간부터 끝 시간까지 반복문을 돌려 배열에 값을 누적해준다
  • 이런식으로 하면 겹치는 시간대를 index로 겹치는 차의 갯수가 저장된다
  • 배열의 크기만큼 반복문을 통해 배열안에 값이 1,2,3인지 판단하여 주차한 차의 갯수당 내는 요금에 주차된 차의 갯수를 곱한 값을 누적해 더해주면 값을 구할 수 있다
profile
게임 개발 지망생

0개의 댓글