组队赛-12
作者:互联网
L-candy machine
用sort过不了,用手写快排过的。
#include <iostream> #include <cstring> #include <algorithm> #include <math.h> using namespace std; typedef long long ll; const int N=1e6+10; ll a[N],sum[N]; void qp(int l,int r,ll a[]) { if (l>=r)return; int i=l-1; int j=r+1; ll x=a[(l+r)/2]; while (i<j) { do i++;while (a[i]<x); do j--;while (a[j]>x); if (i<j)swap(a[i],a[j]); } qp(l,j,a); qp(j+1,r,a); } signed main() { int n; scanf("%d",&n); for (int i=1; i<=n; i++) { scanf("%lld",&a[i]); } qp(1,n,a); sum[1]=a[1]; for (int i=1; i<=n; i++) { sum[i]=sum[i-1]+a[i]; //cout<<sum[i]<<"\n"; } int ans=0; int cnt=0; for (int i=2; i<=n; i++) { int t=sum[i]/i; //cout<<t<<"\n"; if (a[i]>t) { cnt++; int w=i-cnt+1; while (a[w++]<=t)cnt--; } ans=max(ans,cnt); } printf("%d\n",ans); return 0; }
标签:cnt,12,int,ll,++,long,组队,include 来源: https://www.cnblogs.com/Mercury1988/p/16272082.html