این مسابقه به صورت حضوری در تاریخ ۱۴ آذر ۱۴۰۳ در سایت دانشکده برق و کامپیوتر دانشگاه تهران برگزار می‌شود. علاقه‌مندان می‌توانند به صورت همزمان در مسابقه آنلاین که شامل همان سوالات می‌باشد شرکت کنند.

Pop Balloons


  • محدودیت زمان: ۲ ثانیه
  • محدودیت حافظه: ۱۲۸ مگابایت

There are N balloons floating in the air in a large room, lined up from left to right. Young Parva likes to play with arrows and practice her hunting abilities. She shoots an arrow from the left to the right side of the room from an arbitrary height she chooses.

The arrow moves from left to right, at a chosen height hh until it finds a balloon. The moment when an arrow touches a balloon, the balloon pops and disappears and the arrow continues its way from left to right at a height decreased by 1. Therefore, if the arrow was moving at height hh, after popping the balloon it travels on height h1h-1.

Our hero’s goal is to pop all the balloons using as little arrows as possible.

Input🔗

The first line of input contains the integer N.

The second line of input contains an array of N integers hih_i

Each integer hih_i is the height at which the i-th balloon floats, respectively from left to right.

Output🔗

The first and only line of output must contain the minimal number of times Parva needs to shoot an arrow so that all balloons are popped.

Constraints🔗

  • 1N,hi1061 \leq N,h_i \leq 10^6

Sample Test Data🔗

input 1🔗

5
2 1 5 4 3
Plain text

output 1🔗

2
Plain text

input 2🔗

5
4 5 2 1 4
Plain text

output 2🔗

3
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.