Algorithm

[๋ฐฑ์ค€ 2979] ํŠธ๋Ÿญ ์ฃผ์ฐจ

osean 2023. 3. 28. 21:18

๋ฌธ์ œ

 

2979๋ฒˆ: ํŠธ๋Ÿญ ์ฃผ์ฐจ

์ฒซ์งธ ์ค„์— ๋ฌธ์ œ์—์„œ ์„ค๋ช…ํ•œ ์ฃผ์ฐจ ์š”๊ธˆ A, B, C๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ C ≤ B ≤ A ≤ 100) ๋‹ค์Œ ์„ธ ๊ฐœ ์ค„์—๋Š” ๋‘ ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด ์ •์ˆ˜๋Š” ์ƒ๊ทผ์ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํŠธ๋Ÿญ์ด ์ฃผ์ฐจ์žฅ์— ๋„์ฐฉํ•œ ์‹œ๊ฐ„๊ณผ ์ฃผ์ฐจ์žฅ

www.acmicpc.net

ํ’€์ด

#include <bits/stdc++.h>

using namespace std;

int timeCount[101], feeTable[3], parkingTime[3][2], amount;

int main() {
  // ์š”๊ธˆ ํ…Œ์ด๋ธ” ์ž…๋ ฅ
  scanf("%d %d %d", &feeTable[0], &feeTable[1], &feeTable[2]);

  for (int i = 0; i < 3; i++) {
    // ์ฃผ์ฐจ์‹œ๊ฐ„ ์ž…๋ ฅ
    scanf("%d %d", &parkingTime[i][0], &parkingTime[i][1]);
    // ์ฃผ์ฐจ์‹œ๊ฐ„๋งŒํผ ๊ธฐ๋ก
    for (int t = parkingTime[i][0]; t < parkingTime[i][1]; t++) timeCount[t]++;
  }

  // ๊ธฐ๋ก๋œ ์ฃผ์ฐจ์‹œ๊ฐ„๋งŒํผ ์š”๊ธˆ ๊ณ„์‚ฐ
  for (int i = 1; i < 101; i++)
    amount += (feeTable[timeCount[i] - 1] * timeCount[i]);
  printf("%d", amount);
}