EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • šŸ‡²šŸ‡¾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🄰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. CodeNection
  2. 2024
  3. Test Round

Codey and Takoyaki

https://www.hackerrank.com/contests/codenection-2024-test/challenges/cn24-test

Question

Codey runs a popular takoyaki (a Japanese octopus ball) shop. One morning, it finds n customers already waiting in line, each requesting ai takoyaki balls. However, it hasn't started cooking any takoyaki yet.

The grill pan can cook exactly 9 takoyaki balls in one use. For efficiency, Codey always cook at full capacity whenever he uses the pan.

Assuming the number of takoyaki balls Codey have currently is 0, what is the minimum number of times it needs to use his grill pan to fulfill all orders?

Input Format

The first line contains a single integer n - the number of customers in the queue.

The second line contains n space-separated integers, a1, a2, ... , an , where ai represents the number of takoyaki balls the -i-th customer wants to order.

Constraints

1≤n,ai≤1051 \le n,a_i \le 10^51≤n,ai​≤105

Output Format

Output a single integer, the minimum number of times Codey needs to use the grill pan to fulfill all customer orders.

Sample Inputs:

Input

3
5 12 8

Output

3

Solution - Division with ceilings

This is basically a simple math. You can complete this task by simply sum all of the second line, then divide by 9.

But in some cases, simply divide by 9 may cause the number of grills -1 than expected, this is because by the nature of the programming language, if the answer is 3.1, the answer will convert into 3 instead of 4.

Therefore, we need to add a ceil function, which rounds up in any situation to complete the task.

Here's my code below:

import math

t = int(input().strip())
total = sum(list(map(int, input().strip().split())))

print(math.ceil(total / 9))

Note that I had used the math library, and that library is normally allowed on most of the competitive programming. For other programming languages, similar libraries can be found.

PreviousCodey and SundayNextPreliminary Round

Last updated 2 months ago

šŸ‡²šŸ‡¾