Opening ceremonytime limit:5000msmemory limit:524288kbthis problem would be judged onCodeforcesgym. Original id:100502e
64-bit integer IO format: %i64d Java class name: (any)
For the grand opening of the algorithmic games in Nlognsglow, a row of the tower blocks are set to BES demolished in a grand dem Onstration of renewal. Originally the plan is to accomplish this and controlled explosions, one for each tower block, and 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 partic Le Cannon (UKIEPC). Onasingle charge, this cutting-edge contraption can remove either all of the. Oors in a single tower block, or all the x-t H? oors in all the blocks simultaneously, for user's choice of the? Oor number x. In the latter case, the blocks is less than x oors High is left untouched and while for blocks has more than X oo RS, all the oors above the removed x-th one fall down by one level.
Task
Given the number of oors of all towers, output the minimum number of charges needed to eliminate all oors.
Input
The. RST line of input contains the number of blocks N, where 2≤n≤100000. The second line contains n consecutive block heights hi for i =,..., N, where 1≤hi≤1000000. Output output oneline containingone integer:theminimum numberof charges needed totear down all the blocks.
Sample Input 1
6
2 1 8 8 2 3
Sample Output 1
5
Sample Input 2
5
1 1 1) 1 10
Sample Output 2
2
NCPC Problem e:opening Ceremony 9
Problem solving: greedy, to eliminate a row is sure to eliminate the low, to eliminate the whole column of the priority to eliminate high.
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =100010;4 intH[maxn],n;5 intMain () {6 while(~SCANF ("%d",&N)) {7 for(inti =1; I <= N; ++i)8scanf"%d", H +i);9Sort (H +1, h+n+1);Ten intRET =N; One for(inti =1; I <= N; ++i) Aret = min (ret,n-i +h[i]); -printf"%d\n", ret); - } the return 0; -}
View Code
Codeforcesgym 100502E Opening Ceremony