본문 바로가기
Algorithm/백준

[Algorithm][C언어] 백준 15059번: Hard choice

by 8희 2022. 10. 7.

https://www.acmicpc.net/problem/15059

 

15059번: Hard choice

The first line contains three integers Ca, Ba and Pa (0 ≤ Ca, Ba, Pa ≤ 100), representing respectively the number of meals available for chicken, beef and pasta. The second line contains three integers Cr, Br and Pr (0 ≤ Cr, Br, Pr ≤ 100), indicati

www.acmicpc.net

 

문제

In long flights, airlines offer hot meals. Usually the flight attendants push carts containing the meals down along the aisles of the plane. When a cart reaches your row, you are asked right away: “Chicken, beef, or pasta?” You know your choices, but you have only a few seconds to choose and you don’t know how your choice will look like because your neighbor hasn’t opened his wrap yet. . .

The flight attendant in this flight decided to change the procedure. First she will ask all passengers what choice of meal they would prefer, and then she will check if the number of meals available in this flight for each choice are enough.

As an example, consider that the available number of meals for chicken, beef and pasta are respectively (80, 20, 40), while the number of passenger’s choices for chicken, beef and pasta are respectively (45, 23, 48). In this case, eleven people will surely not receive their selection for a meal, since three passengers who wanted beef and eight passengers who wanted pasta cannot be pleased.

Given the quantity of meals available for each choice and the number of meals requested for each choice, could you please help the flight attendant to determine how many passengers will surely not receive their selection for a meal?

 

* 번역

장거리 비행에서, 항공사들은 뜨거운 식사를 제공한다. 보통 승무원들은 기내식이 담긴 카트를 비행기의 통로를 따라 아래로 밀어요. 카트가 줄에 닿으면, 여러분은 즉시 "치킨, 소고기, 파스타?"라고 묻습니다. 여러분은 여러분의 선택을 알고 있지만, 여러분은 선택할 수 있는 시간이 몇 초밖에 없고 여러분의 이웃이 아직 랩을 열지 않았기 때문에 여러분의 선택이 어떻게 보일지 모릅니다.

이 비행기의 승무원은 절차를 바꾸기로 결정했다. 먼저 그녀는 모든 승객들에게 어떤 식사를 더 선호하는지 물어보고, 그 다음 그녀는 이 비행기에서 각각의 선택에 대해 이용할 수 있는 식사 수가 충분한지 확인할 것이다.

예를 들어, 닭고기, 소고기, 파스타의 이용 가능한 식사 수는 각각 (80, 20, 40)이고, 닭고기, 소고기 및 파스타에 대한 승객의 선택 수는 각각 (45, 23, 48)이라고 가정하자. 이 경우 소고기를 원한 승객 3명과 파스타를 원한 승객 8명이 기뻐할 수 없기 때문에 11명이 식사를 위해 선택한 것을 받지 못할 것이 분명하다.

선택 가능한 식사량과 선택 가능한 식사량을 고려하여, 얼마나 많은 승객이 선택을 받지 못할지 승무원이 판단할 수 있도록 도와주실 수 있습니까?

 

입력

The first line contains three integers Ca, Ba and Pa (0 ≤ Ca, Ba, Pa ≤ 100), representing respectively the number of meals available for chicken, beef and pasta. The second line contains three integers Cr, Br and Pr (0 ≤ Cr, Br, Pr ≤ 100), indicating respectively the number of meals requested for chicken, beef and pasta.

 

* 번역

첫 번째 줄은 세 개의 정수 Ca, Ba 및 Pa(0 ≤ Ca, Ba, Pa ≤ 100)를 포함하며, 각각 닭고기, 쇠고기 및 파스타에 사용할 수 있는 식사 수를 나타냅니다. 두 번째 줄은 세 개의 정수 Cr, Br 및 Pr(0 ≤ Cr, Br, Pr ≤ 100)을 포함하며, 각각 닭고기, 쇠고기 및 파스타에 대해 요청된 식사 수를 나타냅니다.

 

출력

Output a single line with an integer representing the number of passengers that will surely not receive their selection for a meal.

 

* 번역

식사에 대한 선택을 확실히 받지 못할 승객의 수를 나타내는 정수로 한 줄을 출력한다.

 

코드

#include <stdio.h>

int main(void) {

  int Ca, Ba, Pa;
  scanf("%d %d %d", &Ca, &Ba, &Pa);
  int Cr, Br, Pr;
  scanf("%d %d %d", &Cr, &Br, &Pr);

  int result = 0;  
  
  if(Ca < Cr) {
    result += Cr - Ca;
  }
  if(Ba < Br){
    result += Br - Ba;
  }
  if(Pa < Pr){
    result += Pr - Pa;
  }

  printf("%d", result);
}

 

영어가 가장 진입장벽인 문제였다. 처음엔 문제를 보고 당황했는데, 막상 영어를 해석한 뒤에 문제를 푸려고 하니 술술 풀렸다!