SOJ.Opening Ceremony

1003. Opening Ceremony
 
 
總提交數量: 123 通過數量: 34
 
     
     
 
時間限制:1秒    內存限制:256兆
題目描述

For the grand opening of the algorithmic games in NlogNsglow, a row of tower blocks is set to be demolished in a grand demonstration of renewal. Originally the plan was to accomplish this with controlled explosions, one for each tower block, but time constraints now require a hastier solution.

To help you remove the blocks more rapidly you have been given the use of a Universal Kinetic / Incandescent Energy Particle Cannon (UKIEPC). On a single charge, this cutting-edge contraption can remove either all of the floors in a single tower block, or all the x-th floors in all the blocks simultaneously, for user’s choice of the floor number x. In the latter case, the blocks that are less than x floors high are left untouched, while for blocks having more than x floors, all the floors above the removed x-th one fall down by one level.

Given the number of floors of all towers, output the minimum number of charges needed to eliminate all floors of all blocks.

輸入格式

The first line of input contains the number of blocks n, where 2 <= n <= 100 000. The second line contains n consecutive block heights hi for i = 1, 2, ..., n, where 1 <= hi <= 1 000 000.

輸出格式

Output one line containing one integer: the minimum number of charges needed to tear down all the blocks.

樣例輸入
將樣例輸入複製到剪貼板
樣例一:
6
2 1 8 8 2 3
樣例二:
5
1 1 1 1 10
樣例輸出
樣例一:
5
樣例二:
2

Problem Source: 2015年每週一賽第四場



#include
#include
#include
using namespace std;
int high[100100];
int main()
{
	int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>high[i];
    sort(high+1,high+1+n);
    int ans=n;
    for(int i=1;i<=n;i++)ans=min(ans,n-i+high[i]);
    cout<

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章