int maxDiff(vector<int> nums) { int sz = nums.size(); if(sz < 2) { return -1; } // construct LMin vector<int> LMin(sz, INT_MAX); LMin[0] = nums[0]; for(int i=1; i<sz; i++) { LMin[i]=min(LMin[i-1], nums[i]); } // connstruct RMax; vector<int> RMax(sz, INT_MIN); RMax[sz-1] = nums[sz-1]; for(int i=sz-2; i>=0; i--) { RMax[i] = max(RMax[i+1], nums[i]); } // get the result int res = -1; int i=0, j=0; while(i<sz && j < sz) { if(LMin[i] < RMax[j]) { res = max(res, j-i); j++; } else { i++; } } return res; }
void cDistRadialeFormelle::AddContrCoeff(cMultiContEQF & aContr) { for (int aK= 2+mDegreFige ; aK<2+mCurDist.NbCoeff() ;aK++) { double aR = RMax(); // std::cout << mTolCoeffs << " " << mTolCoeffs/pow(aR,3+2*(aK-1)) << "\n"; double aTolN = (mTolCoeffs > 0) ? ( mTolCoeffs/pow(aR,3+2*(aK-1))) : mTolCoeffs; AddFoncRappInit(aContr,aK,aK+1,aTolN); } }