작성일 :

문제 링크

24087번 - アイスクリーム (Ice Cream)

설명

목표 높이 이상의 아이스크림을 만들 때 필요한 최소 금액을 구하는 문제입니다.


접근법

기본 아이스크림은 250엔이고, 추가할 때마다 100엔씩 듭니다.

기본 높이로 충분하면 250엔을 출력합니다.

부족하면 필요한 추가 개수를 올림으로 계산하여 비용을 구합니다.



Code

C#

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

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

    var add = 0;
    if (s > a) add = (s - a + b - 1) / b;
    var cost = 250 + add * 100;
    Console.WriteLine(cost);
  }
}

C++

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

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

  int s, a, b;
  if (!(cin >> s >> a >> b)) return 0;
  int add = 0;
  if (s > a) add = (s - a + b - 1) / b;
  int cost = 250 + add * 100;
  cout << cost << "\n";

  return 0;
}