DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord account linking.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Skyline

Back to problem

Editorial

For subtask 1, test every other building for each candidate. This takes O(∑N2)O(\sum N^2)O(∑N2) time, safe because N≤100N\leq100N≤100 and ∑N≤1000\sum N\leq1000∑N≤1000.

For the full task, let LX=max⁡(A1,⋯ ,AX−1)L_X=\max(A_1,\cdots,A_{X-1})LX​=max(A1​,⋯,A and . Use for an empty left range and for an empty right range. The left condition is equivalent to , and the right condition to . Counting exactly the positions satisfying both is therefore correct. Precompute suffix minima from right to left and maintain the prefix maximum while scanning left to right. Equal heights are allowed, so the comparisons are non-strict. Time is and auxiliary space is . Every stored value is at most , and the answer is at most .

Solution written by GPT6.1

X−1
​
)
RX=min⁡(AX+1,⋯ ,AN)R_X=\min(A_{X+1},\cdots,A_N)RX​=min(AX+1​,⋯,AN​)
000
109+110^9+1109+1
LX≤AXL_X\leq A_XLX​≤AX​
AX≤RXA_X\leq R_XAX​≤RX​
O(∑N)O(\sum N)O(∑N)
O(max⁡N)O(\max N)O(maxN)
109+110^9+1109+1
NNN