Algorithm


Problem Name: beecrowd | 2702

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2702

Hard Choice

 

By Inés Kereki, ACM ICPC 2017 UY Uruguay

Timelimit: 1

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?

 

Input

 

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

 

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

 

 

 

Input Samples Output Samples

80 20 40

45 23 48

11

 

 

 

0 0 0

100 100 100

300

 

 

 

41 42 43

41 42 43

0

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
#include <stdlib.h>

int main(void)

{
    int a1, b1, c1, a2, b2, c2, x, y, z, sum=0;

    scanf("%i %i %i %i %i %i", &a1, &b1, &c1, &a2, &b2, &c2);

    x=a1-a2;
    y=b1-b2;
    z=c1-c2;

    if (x  <  0)
        sum+=abs(x);

    if (y < 0)
        sum+=abs(y);

    if (z  <  0)
        sum+=abs(z);

    printf("%i\n", sum);

    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
80 20 40 45 23 48

Output

x
+
cmd
11

#2 Code Example with C++ Programming

Code - C++ Programming


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int chicken1,beef1,pasta1;
	int chicken2,beef2,pasta2;
	scanf("%d%d%d",&chicken1,&beef1,&pasta1);
	scanf("%d%d%d",&chicken2,&beef2,&pasta2);
	int miss=0;
	if(chicken2>chicken1)miss+=(chicken2-chicken1);
	if(beef2>beef1)miss+=(beef2-beef1);
	if(pasta2>pasta1)miss+=(pasta2-pasta1);
	printf("%d\n",miss);
	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
80 20 40 45 23 48

Output

x
+
cmd
11

#3 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("fs")
const [Ca, Ba, Pa, Cr, Br, Pr] = readFileSync("/dev/stdin", "utf8")
	.split(/\s+/, 6)
	.map(value => Number.parseInt(value, 10))

console.log(
	"%d",
	Math.max(0, Cr - Ca) +
	Math.max(0, Br - Ba) +
	Math.max(0, Pr - Pa)
)
Copy The Code & Try With Live Editor

Input

x
+
cmd
80 20 40 45 23 48

Output

x
+
cmd
11
Advertisements

Demonstration


Previous
#2686 Beecrowd Online Judge Solution 2686 The Change Continues!! Solution in C, C++, Java, Js and Python
Next
#2708 Beecrowd Online Judge Solution 2708 Tourists in the Huacachina Park Solution in C, C++, Java, Js and Python