문제
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?
입력
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.
출력
Output a single line with an integer representing the number of passengers that will surely not receive their selection for a meal.
예제 입출력
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
문제 풀이
이 문제는 영어로 되어있어 어려워 보이지만 해석해보면 쉬운 문제였다.
비행기의 기내식으로 3가지의 음식이 있지만 갯수가 한정되어있다. 손님이 선택할 수 있는 횟수가 주어졌을때 각각의 음식이 총 몇 개 부족해지는지를 나타내면 된다.
최종 코드
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector <int> v(3);
vector <int> m(3);
int answer = 0;
cin >> v[0] >> v[1] >> v[2];
cin >> m[0] >> m[1] >> m[2];
for (int i = 0; i < 3; i++) {
if (v[i] - m[i] < 0)
answer += m[i] - v[i];
}
cout << answer;
}
'[Baekjoon] C++ > Bronze' 카테고리의 다른 글
[baekjoon] 5585 : 거스름돈 (C++) (0) | 2024.03.11 |
---|---|
[baekjoon] 11557 : Yangjojang of The Year (C++) (0) | 2023.09.05 |
[baekjoon] 2798 : 블랙잭 (C++) (1) | 2023.08.28 |