작성일 :

문제 링크

25628번 - 햄버거 만들기

설명

빵과 패티로 만들 수 있는 햄버거의 최대 개수를 구하는 문제입니다.


접근법

햄버거 하나에 빵 2개와 패티 1개가 필요합니다.

빵으로 만들 수 있는 수는 빵 개수를 2로 나눈 값이고, 패티로 만들 수 있는 수는 패티 개수 그대로입니다.

둘 중 작은 값이 만들 수 있는 최대 햄버거 수입니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
using System;

class Program {
  static void Main() {
    var p = Array.ConvertAll(Console.ReadLine()!.Split(), int.Parse);
    var buns = p[0];
    var patties = p[1];
    Console.WriteLine(Math.Min(buns / 2, patties));
  }
}

C++

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

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

  int a, b; cin >> a >> b;
  cout << min(a / 2, b) << "\n";

  return 0;
}