<JZOJ5937&luogu3944>斩杀计划&肮脏的牧师
第一次写桶排相关题....
#include<cstdio> #include<iostream> #define rint register int template <class T> inline void read(T &X) { X=0;int W=0;char ch=0; while(!isdigit(ch))W|=ch=='-',ch=getchar(); while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); X=W?-X:X;return; } int n,m,a[5000010],cnt[30010],ans=0,cnt1=0,cnt2=0,cnt3=0,num=-1; int main() { freopen("zhanshajihua.in","r",stdin); freopen("zhanshajihua.out","w",stdout); read(n),read(m); for(rint i=1;i<=n;++i)read(a[i]),cnt[a[i]]++; for(rint i=1;i<=30000-3;i+=3) { ans+=cnt[i];cnt1+=cnt[i]; ans+=cnt[i+1]*2;cnt2+=cnt[i+1]; ans+=cnt[i+2]*3;cnt3+=cnt[i+2]; ++num; if(ans>=m)break; } while(ans>=m+3 && cnt3){ans-=3;--cnt3;} while(ans>=m+1 && cnt1){--ans;--cnt1;} while(ans>=m+2 && cnt2){ans-=2;--cnt2;} if(ans>=m)printf("%d %d\n",num,(cnt1+cnt2)+cnt3*4+num); else printf("-1\n");//luogu “Human Cannot Win Dog” return 0; }