Cover tables with 3-color ribbons

Problem You have an unlimited row of tables and ribbons in 3 colours with counts a, b, c. Each covered table uses one ribbon, and no two adjacent tables may use the same colour. Tables are covered left to right, consecutively. Return the maximum number of tables that can be covered.

Input / Output

  • Input: three non-negative integers a, b, c.
  • Output: the maximum number of consecutively covered tables.

Constraints

  • Counts up to 10^9 — the solution must be O(1)/greedy, not a simulation.

Example

  • a=5, b=1, c=1 → 5 (e.g. A B A C A; the two singles separate the dominant colour).
  • a=2, b=2, c=2 → 6 (all ribbons usable).
asked …
LeaderboardSalaryAccount