Topic links
Give the number of N, let you get rid of some number, so that the average of the remaining number-the difference between the median number is the largest.
Sort the array first, then enumerate each number as the median, for each enumeration of the number of its left and right intervals to find a mean maximum, the average is the largest, it must be the number of its left is close to his number, the number of the rightmost number is the rightmost few. The maximum value is then taken in all cases.
The three-point notation Lmid = (l*2+r)/2, Rmid = (l+r*2+2)/3, learned.
And the average is best not to divide, say the average-median, then write these numbers and-median * length.
1#include <iostream>2#include <vector>3#include <cstdio>4#include <cstring>5#include <algorithm>6#include <cmath>7#include <map>8#include <Set>9#include <string>Ten#include <queue> One#include <stack> A#include <bitset> - using namespacestd; - #definePB (x) push_back (x) the #definell Long Long - #defineMK (x, y) make_pair (x, y) - #defineLson L, M, rt<<1 - #defineMem (a) memset (a, 0, sizeof (a)) + #defineRson m+1, R, rt<<1|1 - #defineMem1 (a) memset (a,-1, sizeof (a)) + #defineMEM2 (a) memset (a, 0x3f, sizeof (a)) A #defineRep (i, N, a) for (int i = A; i<n; i++) at #defineFi first - #defineSe Second -typedef pair<int,int>PLL; - Const DoublePI = ACOs (-1.0); - Const DoubleEPS = 1e-8; - Const intMoD = 1e9+7; in Const intINF =1061109567; - Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} }; to Const intMAXN = 2e5+5; + ll A[MAXN], SUM[MAXN]; - intN; theLL Cal (intLenintPOS) { *ll num = sum[pos]-sum[pos-len-1]+sum[n]-sum[n-Len]; $ returnnum;Panax Notoginseng } - intMain () the { +Cin>>N; A for(inti =1; i<=n; i++) { thescanf"%i64d", &a[i]); + } - if(n = =1|| n = =2) { $cout<<1<<Endl; $cout<<a[1]<<Endl; - return 0; - } theSort (A +1, A +1+n); -LL Maxx =0;Wuyi intLen =0, Mid =1; the for(inti =1; i<=n; i++) -Sum[i] = sum[i-1]+A[i]; Wu for(inti =2; i<=n-1; i++) { - intL =0, r = min (i-1, N-i); About while(l<r) { $ intLmid = (2*L+R)/3; - intRmid = (L +2*r+2)/3; -ll ans1 =cal (Lmid, i); -ll ans2 =cal (Rmid, i); A if(Ans1* (2*rmid+1) < (2*lmid+1)*ans2) { +L = lmid+1; the}Else { -r = rmid-1; $ } the } thell tmp = (sum[i]-sum[i-l-1]+SUM[N]-SUM[N-L])-(2*l+1)*A[i]; the if(Tmp* (2*len+1) >maxx* (2*l+1)) { theMaxx =tmp; -Len =l; inMID =i; the } the } Aboutcout<<2*len+1<<Endl; the for(inti = Mid-len; i<=mid; i++) theprintf"%d", A[i]); the for(inti = n-len+1; i<=n; i++) +printf"%d", A[i]); - return 0; the}
Codeforces 626E. Simple skewness three points