작성일 :

문제 링크

25191번 - 치킨댄스를 추는 곰곰이를 본 임스

설명

가게에 있는 치킨 개수와 집에 있는 콜라, 맥주 개수가 주어질 때, 주문 가능한 치킨의 최대 개수를 구하는 문제입니다. 치킨 1마리를 먹으려면 콜라 2개 또는 맥주 1개가 필요합니다.


접근법

먼저, 음료로 먹을 수 있는 치킨 수를 계산합니다. 콜라는 2개당 1마리, 맥주는 1개당 1마리이므로 콜라 개수를 2로 나눈 값에 맥주 개수를 더합니다.

다음으로, 가게 재고를 초과할 수 없으므로 가게 치킨 수와 음료로 먹을 수 있는 치킨 수 중 작은 값이 답이 됩니다.



Code

C#

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

namespace Solution {
  class Program {
    static void Main(string[] args) {
      var n = int.Parse(Console.ReadLine()!);
      var s = Console.ReadLine()!.Split();
      var a = int.Parse(s[0]);
      var b = int.Parse(s[1]);
      var drinkChicken = a / 2 + b;
      Console.WriteLine(Math.Min(n, drinkChicken));
    }
  }
}

C++

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

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

  int n, a, b;
  cin >> n >> a >> b;

  int drinkChicken = a / 2 + b;
  cout << min(n, drinkChicken) << "\n";

  return 0;
}