작성일 :

문제 링크

20233번 - Bicycle

설명

두 자전거 요금제의 한 달 총 비용을 각각 구하는 문제입니다.


접근법

요금제 1은 하루 30분, 요금제 2는 하루 45분까지 무료이고 초과 시간에 대해 분당 요금이 부과됩니다.

21일 동안 매일 동일하게 사용하므로, 하루 초과 시간에 분당 요금을 곱하고 21을 곱하면 총 추가 요금이 됩니다.

기본요금에 추가요금을 더한 값이 각 요금제의 총 비용입니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;

class Program {
  static void Main() {
    var a = int.Parse(Console.ReadLine()!);
    var x = int.Parse(Console.ReadLine()!);
    var b = int.Parse(Console.ReadLine()!);
    var y = int.Parse(Console.ReadLine()!);
    var t = int.Parse(Console.ReadLine()!);

    var costA = a + (t > 30 ? 21 * (t - 30) * x : 0);
    var costB = b + (t > 45 ? 21 * (t - 45) * y : 0);

    Console.WriteLine($"{costA} {costB}");
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, x, b, y, t; cin >> a >> x >> b >> y >> t;
  int costA = a + (t > 30 ? 21 * (t - 30) * x : 0);
  int costB = b + (t > 45 ? 21 * (t - 45) * y : 0);
  cout << costA << " " << costB << "\n";

  return 0;
}