fork(1) download
  1. #include "ricehub.h"
  2.  
  3. #define MAXN 100005
  4. typedef long long lld;
  5.  
  6. static int N; lld X[MAXN],S[MAXN];
  7.  
  8. lld get_sum(int s,int e,int t)
  9. {
  10. return S[e]-S[t]-X[t]*(e-t)+X[t]*(t-s)-(S[t-1]-S[s-1]);
  11. }
  12.  
  13. int besthub(int n, int L, int x[], lld B)
  14. {
  15. int i,s,e,ans=0;
  16. N = n;
  17. for (i=0;i<N;i++) X[i+1] = x[i];
  18. for (i=1;i<=N;i++) S[i] = S[i-1]+X[i];
  19. for (s=e=1;e<=N;e++){
  20. while (s < e && get_sum(s,e,(s+e)>>1) > B) s++;
  21. if (ans < e-s+1) ans = e-s+1;
  22. }
  23. return ans;
  24. }
  25.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty