Skip to main content
Back to problems
Codeforces
Easy
Math
Greedy
Giga Tower

Determine the maximum possible height of a tower built from a sequence of blocks under simple stacking rules.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Giga Tower

You are given a sequence of blocks with different heights. Build a tower by taking blocks in order and applying the rule that each next chosen block must satisfy the tower condition from the previous one.

Your task is to compute the best achievable tower height according to the problem's stacking rule.

This is an implementation-style problem where the key is to process the blocks carefully and track the current best tower state as you scan through the input.

Input Format

  • The first line contains an integer nn — the number of blocks.
  • The second line contains nn integers describing the block values/heights.

Output Format

  • Print a single integer: the maximum tower value/height that can be obtained.

Constraints

  • 1n1051 \le n \le 10^5
  • Block values fit in standard 32-bit signed integers
  • Use an O(n)O(n) or O(nlogn)O(n \log n) approach
Examples
Sample cases returned by the problem API.

Example 1

Input

5
1 2 3 2 5

Output

5

Explanation

A valid tower can be formed by choosing blocks so that the tracked tower value reaches 5.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.