Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Codeforces Round 956/C. Have Your Cake and Eat It Too
PrevNext
CodeforcesCodeforces
Specialist
Codeforces Round 956

C. Have Your Cake and Eat It Too

GreedyArray
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

Alice, Bob and Charlie want to share a rectangular cake cut into π‘› pieces. Each person considers every piece to be worth a different value. The π‘–-th piece is considered to be of value π‘Žπ‘– by Alice, 𝑏𝑖 by Bob and π‘π‘– by Charlie.

The sum over all π‘Žπ‘–, all π‘π‘– and all𝑐𝑖 individually is the same, equal to π‘‘π‘œπ‘‘.

Given the values of each piece of the cake for each person, you need to give each person a contiguous slice of cake. In other words, the indices at the left and right ends of these subarrays (the slices given to each person) can be represented as (π‘™π‘Ž,π‘Ÿπ‘Ž), (𝑙𝑏,π‘Ÿπ‘) and (𝑙𝑐,π‘Ÿπ‘) respectively for Alice, Bob and Charlie. The division needs to satisfy the following constraints:

  • No piece is assigned to more than one person, i.e., no two subarrays among [π‘™π‘Ž,…,π‘Ÿπ‘Ž], [𝑙𝑏,…,π‘Ÿπ‘] and [𝑙𝑐,…,π‘Ÿπ‘] intersect.
  • βˆ‘π‘–=π‘™π‘Žπ‘Ÿπ‘Žπ‘Žπ‘–,βˆ‘π‘–=π‘™π‘π‘Ÿπ‘π‘π‘–,βˆ‘π‘–=π‘™π‘π‘Ÿπ‘π‘π‘–β‰₯βŒˆπ‘‘π‘œπ‘‘3βŒ‰.

Here, the notation βŒˆπ‘Žπ‘βŒ‰ represents ceiling division. It is defined as the smallest integer greater than or equal to the exact division of π‘Ž by π‘. In other words, it rounds up the division result to the nearest integer. For instance⌈103βŒ‰=4 and βŒˆ153βŒ‰=5.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Codeforces Round 956
Previous ProblemNext Problem