백준/브론즈
[백준] 브론즈2-트럭 주차 C++ 2979번
taene_
2025. 2. 21. 23:54
https://www.acmicpc.net/problem/2979
// 시각은 [이상, 미만) 범위다.
#include <iostream>
using namespace std;
int A, B, C, sum;
int cnt[100];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> A >> B >> C;
for (int i = 0; i < 3; i++)
{
int start, end;
cin >> start >> end;
for (int j = start; j < end; j++)
cnt[j]++;
}
for (int i = 0; i < 100; i++)
{
if (cnt[i])
{
if (cnt[i] == 1)
{
sum += A;
}
else if (cnt[i] == 2)
{
sum += B * 2;
}
else if (cnt[i] == 3)
{
sum += C * 3;
}
}
}
cout << sum << '\n';
return 0;
}
// 2회차 풀이
#include <iostream>
using namespace std;
int a, b, c;
int arr[102];
int sum;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b >> c;
for (int i = 0; i < 3; i++)
{
int x, y;
cin >> x >> y;
for (int j = x; j < y; j++)
{
arr[j]++;
}
}
for (int i = 1; i <= 100; i++)
{
if (arr[i] == 0) continue;
else if (arr[i] == 1)
sum += a;
else if (arr[i] == 2)
sum += b * 2;
else if (arr[i] == 3)
sum += c * 3;
}
cout << sum;
return 0;
}