Algorithm


Problem Name: beecrowd | 3170

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

Christmas Balls

 

By Jessica Dagostini, beecrowd BR Brazil

Timelimit: 1

Amelia loves Christmas, and her favorite part on this date is setting up the Christmas tree! She loves to decorate the tree with polka dots and colorful lights, so it looks bright and fun! However, Amélia likes things well distributed and demands that her tree has no more than half of branches in balls. So, if your Christmas tree has G branches, it needs G / 2 marbles. If the G number of branches is odd, that value will be rounded down.

This year, Amélia decided to update her tree and will buy a new one. Also, some of her balls broke, and she will need to know how many new balls she will need to buy to keep her tree balanced the way she likes it!

For that, she wants your help! Given the number of balls Amelia has and the number of branches her new tree will have, tell Amelia how many Christmas balls she needs to buy to decorate her new tree!

 

Input

 

The input consists of two integer values, read on two lines, B (1 < B < 103) and G (100 < G < 1000) indicating, respectively, the number of balls that Amélia already has and the number of branches of her new Christmas tree.

 

Output

 

Print the number of balls Amélia needs to buy to complete her tree, with the message "Faltam B bolinha(s)" (in English, Missing B ball(s)), where B is the number of balls that Amelia needs to buy. If Amelia has enough balls to spare, print the message "Amelia tem todas bolinhas!" (in English, "Amelia has all balls!")

 

 

 

Exemplos de Entrada Exemplos de Saída

300
700

Faltam 50 bolinha(s)

 

 

 

300
600

Amelia tem todas bolinhas!

 

 

 

300
701

Faltam 50 bolinha(s)

 

Code Examples

#1 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("node:fs")
const [B, G] = readFileSync("/dev/stdin", "utf8")
	.split("\n", 2)
	.map(value => Number.parseInt(value, 10))

const D = Math.floor(G / 2) - B

console.log(D <= 0 ? "Amelia tem todas bolinhas!" : `Faltam ${D} bolinha(s)`)
Copy The Code & Try With Live Editor

Input

x
+
cmd
300 700

Output

x
+
cmd
Faltam 50 bolinha(s)

#2 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var prompt = function(texto) { return lines.shift(); };

var x = parseInt(prompt(""))
var y = parseInt(prompt(""))
var k = Math.trunc(y/2) - x

if(k <= 0){
    console.log("Amelia tem todas bolinhas!")
}else{
    console.log("Faltam " + k + " bolinha(s)">
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
300 700

Output

x
+
cmd
Faltam 50 bolinha(s)

#3 Code Example with Python Programming

Code - Python Programming


b=int(input())
g=int(input())

if g%2!=0:g-=1
if g<=b*2:print("Amelia tem todas bolinhas!")
else:
    aux=(g-(2*b))/2
    print(f'Faltam {aux:.0f} bolinha(s)')

Copy The Code & Try With Live Editor

Input

x
+
cmd
300 700

Output

x
+
cmd
Faltam 50 bolinha(s)
Advertisements

Demonstration


Previous
#3167 Beecrowd Online Judge Solution 3167 Finding Words on Secondary Diagonal Solution in C, C++, Java, Js and Python
Next
#3173 Beecrowd Online Judge Solution 3173 Christmas Star Solution in C, C++, Java, Js and Python