Test instructions: N Tower, the first tower is composed of $h_i$ cube, each time can be cut to a height of more than H K Cube, ask you to cut the minimum number of times, you can make all tower height equal
K>=n, N<=2e5
Idea: Differential statistics each height I have the number of blocks nh[i], and then from high to low greedy cut on the line
Code:
#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>//#include <stack>#include <queue>#include<deque>#include<Set>#include<vector>#include<map>#include<functional>#defineFST First#defineSC Second#definePB Push_back#defineMem (A, B) memset (A,b,sizeof (a))#defineLson l,mid,root<<1#defineRson mid+1,r,root<<1|1#defineLC Root<<1#defineRC Root<<1|1#defineLowbit (x) ((x) & (-X))using namespaceStd;typedefDoubleDb;typedefLong DoubleLdb;typedefLong Longll;typedef unsignedLong LongUll;typedef pair<int,int>Pi;typedef pair<ll,ll>PLL;ConstDB EPS = 1e-6;Const intMoD =100003;Const intMAXN = 2e5+ -;Const intMAXM = 2e5+ -;Constll inf =0x3f3f3f3f3f3f3f3f;ConstDB PI = ACOs (-1.0);intNH[MAXN];intMain () {intN;ll m; scanf ("%d%lld", &n, &m); intvol =0; for(inti =1; I <= N; i++){ intC; scanf ("%d", &c); nh[0]++;nh[c+1]--; } for(inti =1; I <= MAXN; i++) {Nh[i]+=nh[i-1]; } intTMP =0; intAns =0; for(inti = MAXN; I >=0; i--){ if(nh[i]==n) Break; if(tmp+nh[i]>m) {tmp=Nh[i]; Ans++; } Elsetmp+=Nh[i]; } if(tmp>0) ans++; printf ("%d", ans); return 0;}
Codeforces 1065C make It Equal (differential + greedy)