#include <bits/stdc++.h>
#define rep(i,x,y) for (int i = (x); i<=(y); i++)
#define repe(i,x,y) for (int i = (x); i < (y);i++)
#define drep(i,x,y) for (int i = (x); i >= (y); i--)
#define mp make_pair
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define sf(n) scanf("%Lf",&n)
#define prf(n) printf("%Lf",n)
#define	s(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define endc printf("\n")
#define psp printf(" ")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;

const int maxn = 2e5 + 7;

inline bool fracsort(pii a, pii b) {
	return a.first * b.second < a.second * b.first;
}

inline bool eq (const pii a, const pii b) {
	return a.first * b.second == a.second * b.first;
}
inline bool neq (const pii a, const pii b) {
	return a.first * b.second != a.second * b.first;
}

pii A[maxn];
set<pii> S[maxn];
int gr[maxn];
pii B[maxn];
ll before[maxn];
ll after[maxn];
ld least[maxn];
ld most[maxn];
ld T;
set<ld> tiny;

int n;

bool valid(ld c) {

	ld last = 1e9; tiny.clear();

	drep(q,n,1) { // in decreasing p order

		if (B[q].first != last) {
			for (int p = q+1; p<=n && B[p].first == last; p++) {
				tiny.insert(least[B[p].second]);
			}
		}

		int i = B[q].second;
		int g = gr[i];

		last = B[q].first;

		most[i] = A[i].first * (1 - (c * (ld)(before[g] + A[i].second) / T));
		least[i] = A[i].first * (1 - (c * (ld)after[g] / T));

		//cout<<c<<" > "<<i<<" : "<<least[i]<<" : "<<most[i]<<endl;

		if (tiny.size() > 0 && *tiny.begin() < most[i]) {
			return false;
		}

	}

	return true;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n;
	rep(i,1,n) {
		cin>>A[i].first;
	}
	rep(i,1,n) {
		cin>>A[i].second;
	}

	sort(A+1,A+n+1,fracsort);

	cout<<fixed;

	reverse(A+1,A+n+1);

	int pos = 0;
	A[0] = mp(0,-1);

	rep(i,1,n) {
		if (neq(A[i],A[i-1])) {
			pos++; S[pos].clear();
		}
		S[pos].insert(A[i]);

		//cout<<A[i].first<<" : "<<A[i].second<<" : "<<pos<<endl;

		gr[i] = pos;

		B[i] = mp(A[i].first, i);
	}

	sort(B+1,B+n+1);

	T = 0;

	ll clk = 0;

	gr[0] = -1;

	rep(i,1,n) {

		if (gr[i] != gr[i-1]) {
			before[gr[i]] = clk;
		}

		clk += A[i].second;

		after[gr[i]] = clk;

		T += (ld)A[i].second;

		//cout<<i<<" : "<<before[gr[i]]<<" : "<<after[gr[i]]<<endl;
	}

	ld l = 0.0, r = 1.0;
	rep(iter,1,100) {
		ld mid = (l+r)/2;

		if (valid(mid)) {
			l = mid;
		} else {
			r = mid;
		}
	}

	cout<<setprecision(12);
	cout<<l<<endl;
}


#include <bits/stdc++.h>
#define rep(i,x,y) for (int i = (x); i<=(y); i++)
#define repe(i,x,y) for (int i = (x); i < (y);i++)
#define drep(i,x,y) for (int i = (x); i >= (y); i--)
#define mp make_pair
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define sf(n) scanf("%Lf",&n)
#define prf(n) printf("%Lf",n)
#define	s(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define endc printf("\n")
#define psp printf(" ")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;

const int maxn = 2e5 + 7;

inline bool fracsort(pii a, pii b) {
	return a.first * b.second < a.second * b.first;
}

inline bool eq (const pii a, const pii b) {
	return a.first * b.second == a.second * b.first;
}
inline bool neq (const pii a, const pii b) {
	return a.first * b.second != a.second * b.first;
}

pii A[maxn];
set<pii> S[maxn];
int gr[maxn];
pii B[maxn];
ll before[maxn];
ll after[maxn];
ld least[maxn];
ld most[maxn];
ld T;
set<ld> tiny;

int n;

bool valid(ld c) {

	ld last = 1e9; tiny.clear();

	drep(q,n,1) { // in decreasing p order

		if (B[q].first != last) {
			for (int p = q+1; p<=n && B[p].first == last; p++) {
				tiny.insert(least[B[p].second]);
			}
		}

		int i = B[q].second;
		int g = gr[i];

		last = B[q].first;

		most[i] = A[i].first * (1 - (c * (ld)(before[g] + A[i].second) / T));
		least[i] = A[i].first * (1 - (c * (ld)after[g] / T));

		//cout<<c<<" > "<<i<<" : "<<least[i]<<" : "<<most[i]<<endl;

		if (tiny.size() > 0 && *tiny.begin() < most[i]) {
			return false;
		}

	}

	return true;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n;
	rep(i,1,n) {
		cin>>A[i].first;
	}
	rep(i,1,n) {
		cin>>A[i].second;
	}

	sort(A+1,A+n+1,fracsort);

	reverse(A+1,A+n+1);

	int pos = 0;
	A[0] = mp(0,-1);

	rep(i,1,n) {
		if (neq(A[i],A[i-1])) {
			pos++; S[pos].clear();
		}
		S[pos].insert(A[i]);

		//cout<<A[i].first<<" : "<<A[i].second<<" : "<<pos<<endl;

		gr[i] = pos;

		B[i] = mp(A[i].first, i);
	}

	sort(B+1,B+n+1);

	T = 0;

	ll clk = 0;

	gr[0] = -1;

	rep(i,1,n) {

		if (gr[i] != gr[i-1]) {
			before[gr[i]] = clk;
		}

		clk += A[i].second;

		after[gr[i]] = clk;

		T += (ld)A[i].second;

		//cout<<i<<" : "<<before[gr[i]]<<" : "<<after[gr[i]]<<endl;
	}

	ld l = 0.0, r = 1.0;
	rep(iter,1,100) {
		ld mid = (l+r)/2;

		if (valid(mid)) {
			l = mid;
		} else {
			r = mid;
		}
	}

	cout<<setprecision(12);
	cout<<l<<endl;
}


#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define F first
#define S second
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
  return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
  s<<"[ ";
  for (auto it : c) s << it << " ";
  s<<"]";
  return s;
}
// Let's Fight!

typedef long long ll;
typedef pair<ll, ll> pll;

const int MAXN = 151515;

int N;
ll T;
pll arr[MAXN];
double smin[MAXN], smax[MAXN];

int V;
vector<int> vdisc;
vector<int> vbox[MAXN];

bool cmp(pll a, pll b)
{
  return a.F*b.S > a.S*b.F;
}

bool equal(pll a, pll b)
{
  return a.F*b.S == a.S*b.F;
}

bool check(double c)
{
  int pos = 0;
  ll time = 0;
  while(pos < N)
  {
    int rb = pos+1;
    while(rb < N && equal(arr[pos], arr[rb]))
      rb++;

    ll tf = time;
    for(int i=pos; i<rb; i++)
      tf += arr[i].S;

    for(int i=pos; i<rb; i++)
    {
      smax[i] = arr[i].F * (1 - (c * (time + arr[i].S)) / T);
      smin[i] = arr[i].F * (1 - (c * tf) / T);
    }

    pos = rb;
    time = tf;
  }

  double curmax = -1E20;

  for(int i=0; i<V; i++)
  {
    for(auto x: vbox[i])
      if(curmax > smin[x])
        return false;
    for(auto x: vbox[i])
      curmax = max(curmax, smax[x]);
  }

  return true;
}

double calc()
{
  sort(arr, arr+N, cmp);
  T = 0;
  for(int i=0; i<N; i++)
    T += arr[i].S;

  for(int i=0; i<N; i++)
    vdisc.PB(arr[i].F);

  sort(ALL(vdisc));
  V = unique(ALL(vdisc)) - vdisc.begin();
  vdisc.resize(V);

  for(int i=0; i<N; i++)
  {
    int pos = lower_bound(ALL(vdisc), arr[i].F) - vdisc.begin();
    vbox[pos].PB(i);
  }

  //for(int i=0; i<N; i++) cout<<arr[i]<<" ";cout<<endl;

  double lb = 0, rb = 1;
  for(int i=0; i<35; i++)
  {
    double mb = (lb + rb) / 2;
    if(check(mb))
      lb = mb;
    else
      rb = mb;
  }
  return lb;
}

int main() {
  IOS;

  cin>>N;
  for(int i=0; i<N; i++)
    cin>>arr[i].F;
  for(int i=0; i<N; i++)
    cin>>arr[i].S;

  double ans = calc();
  cout<<fixed<<setprecision(10)<<ans<<endl;

  return 0;
}


/*
 *************************
 Id  : Matrix.code
 Task:
 Date: 2016-04-03

 **************************
 */

#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<unordered_map>
#include<assert.h>
using namespace std;
/*------- Constants---- */

#define Long                    long long
#define Ulong                   unsigned long long
#define forn(i,n)               for( int i=0 ; i < n ; i++ )
#define mp(i,j)                 make_pair(i,j)
#define pb(a)                   push_back((a))
#define SZ(a)                   (int) a.size()
#define all(x)                  (x).begin(),(x).end()
#define gc                      getchar_unlocked
#define PI                      acos(-1.0)
#define EPS                     1e-9
#define xx                      first
#define yy                      second
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define Di(x)                   int x;scanf("%d",&x)
#define min(a,b)                ((a)>(b) ? (b) : (a) )
#define max(a,b)                ((a)>(b) ? (a):(b))
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))

/*************************** END OF TEMPLATE ****************************/

const int N = 1.5e5+5;

long long p[N],t[N],w[N],T=0;
pair<long long,long long> pl[N];
double iMin[N],iMax[N];
int o[N];
int n;
bool cmp(int a,int b)
{
    return p[a]*t[b] > p[b] * t[a];
}
bool eq(int a,int b)
{
    return p[a]*t[b] == p[b]*t[a];
}

bool check(double c)
{
    long long x = 0;

    for(int i= 0;i<n; ){
        int j = i;
        long long nx = x;
        for(; j< n && eq(o[i],o[j]); j ++){
            nx+=t[o[j]];
        }
        for(; i < j; i ++) {
            iMin[o[i]] = p[o[i]] * (1 - c * nx/T);
            iMax[o[i]] = p[o[i]] * (1 - c * (x+t[o[i]])/T);
        }
        i=j;
        x=nx;
    }

    double maxt= -1;
    for(int i = 0; i < n; ){
        int j = i;
        for(; j <n && p[i]== p[j]; j++ ) {
            if(iMin[j] < maxt ) return false;
         }
         for(;i<j;i++) maxt= max(maxt,iMax[i]);
         i=j;
    }
    return true;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lld",&pl[i].xx);
    for(int i= 0;i<n;i ++) scanf("%lld",&pl[i].yy);
    sort(pl,pl+n);
    for(int i = 0;i < n; i ++) {
        p[i]=pl[i].xx;
        t[i]=pl[i].yy;
        T += t[i];
    }
    for(int i=0;i < n;i++) o[i]= i;
    sort(o,o+n,cmp);

    double L=0,H=1,ans=0,mid ;
    for(int i=0;i < 64; i++) {
        mid = (L+H)/2;
        if(check(mid)) {
            ans = mid;
            L = mid;
        }
        else H = mid;
    }
    printf("%.10f\n",ans);

    return 0;
}


#include <set>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define sz(a) static_cast<int>(a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fillchar(a, x) memset(a, x, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
typedef vector<string> VS;
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

struct Prob {
    LL p, t, x1, x2;
    bool operator<(const Prob& other) const {
        return p*other.t>other.p*t;
    }
    double min_score(double c, LL T) const {
        return (double)p*(1-c*(double)x2/(double)T);
    }
    double max_score(double c, LL T) const {
        return (double)p*(1-c*(double)x1/(double)T);
    }
};

void solve(vector<Prob> ps, LL T) {
    sort(all(ps), [](const Prob& a, const Prob& b) { return a.p<b.p; });
    double le=0, ri=1;
    repn(_t, 60) {
        double c=(le+ri)/2;
        double max_score=0;
        bool ok=true;
        for(const auto& p: ps) {
            if(p.min_score(c, T)+1e-8<max_score) {
                ok=false; break;
            }
            setmax(max_score, p.max_score(c, T));
        }
        if(ok) le=c;
            else ri=c;
    }
    printf("%.9lf\n", le);
}

int main() {
    int n; scanf("%d", &n);
    vector<Prob> ps(n);
    for(auto& p: ps) { int x; scanf("%d", &x); p.p=x; }
    for(auto& p: ps) { int x; scanf("%d", &x); p.t=x; }
    sort(all(ps));
    LL sx=0;
    for(int i=0, j; i<n; i=j) {
        for(j=i; j<n && !(ps[i]<ps[j]); ++j);
        LL tx=sx; rep(k, i, j-1) tx+=ps[k].t;
        rep(k, i, j-1) {
            ps[k].x1=sx+ps[k].t;
            ps[k].x2=tx;
        }
        sx=tx;
    }
    solve(ps, sx);
    return 0;
}


#include <set>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define sz(a) static_cast<int>(a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fillchar(a, x) memset(a, x, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
typedef vector<string> VS;
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

struct Prob {
    LL p, t, x1, x2;
    bool operator<(const Prob& other) const {
        return p*other.t>other.p*t;
    }
    double min_score(double c, LL T) const {
        return (double)p*(1-c*(double)x2/(double)T);
    }
    double max_score(double c, LL T) const {
        return (double)p*(1-c*(double)x1/(double)T);
    }
};

void solve(vector<Prob> ps, LL T) {
    sort(all(ps), [](const Prob& a, const Prob& b) { return a.p<b.p; });
    double le=0, ri=1;
    repn(_t, 60) {
        double c=(le+ri)/2;
        double max_score=0;
        bool ok=true;
        for(int i=0, j; i<sz(ps); i=j) {
            for(j=i; j<sz(ps) && ps[i].p==ps[j].p; ++j);
            rep(k, i, j-1) if(ps[k].min_score(c, T)+1e-8<max_score) {
                ok=false; break;
            }
            if(!ok) break;
            rep(k, i, j-1) setmax(max_score, ps[k].max_score(c, T));
        }
        if(ok) le=c;
            else ri=c;
    }
    printf("%.9lf\n", le);
}

int main() {
    int n; scanf("%d", &n);
    vector<Prob> ps(n);
    for(auto& p: ps) { int x; scanf("%d", &x); p.p=x; }
    for(auto& p: ps) { int x; scanf("%d", &x); p.t=x; }
    sort(all(ps));
    LL sx=0;
    for(int i=0, j; i<n; i=j) {
        for(j=i; j<n && !(ps[i]<ps[j]); ++j);
        LL tx=sx; rep(k, i, j-1) tx+=ps[k].t;
        rep(k, i, j-1) {
            ps[k].x1=sx+ps[k].t;
            ps[k].x2=tx;
        }
        sx=tx;
    }
    solve(ps, sx);
    return 0;
}


#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

struct Frac {
  int num, den;
  bool operator<(const Frac& other) const {
    return num * other.den > other.num * den;
  }
};

map<Frac, vector<PII>> mapka;
typedef pair<LD, LD> PLD;
const int N = 2e5 + 5;
int p[N], t[N];
#undef int
int main() {
#define int long long

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;

  int n;
  cin>>n;
  RE (i, n) {
    cin>>p[i];
  }
  int T = 0;
  RE (i, n) {
    cin>>t[i];
    T += t[i];
  }
  RE (i, n) {
    mapka[{p[i], t[i]}].PB({p[i], t[i]});
  }
  for (auto& vvv : mapka) {
    sort(ALL(vvv.nd));
  }

  LD kl = 0, kp = 1, faj = 0;
  while (kp - kl > 1e-7) {
    LD aktc = (kl + kp) / 2;
    int so_far = 0;
    set<pair<int, LD>> max_scores;
    bool can_par = 0;
    for (auto& vvv : mapka) {
      auto& v = vvv.nd;
      debug(v);
      int t_here = 0;
      for (auto& el : v) {
        t_here += el.nd;
      }
      for (auto& el : v) {
        LD max_score = el.st * (1 - aktc * (so_far + el.nd) / T);
        LD min_score = el.st * (1 - aktc * (so_far + t_here) / T);
        debug(max_score, min_score, el.st, el.nd);
        auto it_max = max_scores.upper_bound({el.st, -1});
        if (it_max != max_scores.begin()) {
          it_max--;
          if (it_max->nd > min_score) {
            can_par = 1;
          }
        }
        max_scores.insert({el.st, max_score});
      }
      so_far += t_here;
    }
    if (can_par) {
      kp = aktc;
    } else {
      faj = aktc;
      kl = aktc;
    }
  }
  cout<<faj<<endl;

  return 0;
}


#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

struct Frac {
  int num, den;
  bool operator<(const Frac& other) const {
    return num * other.den > other.num * den;
  }
};

map<Frac, vector<PII>> mapka;
typedef pair<LD, LD> PLD;
const int N = 2e5 + 5;
int p[N], t[N];
#undef int
int main() {
#define int long long

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;

  int n;
  cin>>n;
  RE (i, n) {
    cin>>p[i];
  }
  int T = 0;
  RE (i, n) {
    cin>>t[i];
    T += t[i];
  }
  RE (i, n) {
    mapka[{p[i], t[i]}].PB({p[i], t[i]});
  }
  for (auto& vvv : mapka) {
    sort(ALL(vvv.nd));
  }

  LD kl = 0, kp = 1, faj = 0;
  while (kp - kl > 1e-7) {
    LD aktc = (kl + kp) / 2;
    int so_far = 0;
    set<pair<int, LD>> max_scores;
    bool can_par = 0;
    for (auto& vvv : mapka) {
      auto& v = vvv.nd;
      debug(v);
      int t_here = 0;
      for (auto& el : v) {
        t_here += el.nd;
      }
      for (auto& el : v) {
        LD max_score = el.st * (1 - aktc * (so_far + el.nd) / T);
        LD min_score = el.st * (1 - aktc * (so_far + t_here) / T);
        debug(max_score, min_score, el.st, el.nd);
        auto it_max = max_scores.upper_bound({el.st, 1e9});
        if (it_max != max_scores.begin()) {
          it_max--;
          if (it_max->nd > min_score) {
            can_par = 1;
          }
        }
        max_scores.insert({el.st, max_score});
      }
      so_far += t_here;
    }
    if (can_par) {
      kp = aktc;
    } else {
      faj = aktc;
      kl = aktc;
    }
  }
  cout<<faj<<endl;

  return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define all(a) (a).begin(), (a).end()

#define equal equalll
#define less lesss
const int N = 2e5;
const long long INF = 1e9 + 19;
const int T = 60;

struct Prob {
    long long p, t;
    int id;
    bool operator == (Prob other) {
        return t * other.p == other.t * p;
    }
};

int n;
Prob b[N];

void read() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld", &b[i].p);
    for (int i = 0; i < n; i++)
        scanf("%lld", &b[i].t);
}

bool cmpP(Prob A, Prob B) {
    if (A == B) {
        return A.p < B.p;
    }
    return A.t * B.p < B.t * A.p;
}

long long sumT = 0;

double mn[N];
double mx[N];
long long pp[N];

bool check(double c) {
    long long tmr = 0;
    for (int i = 0; i < n; ) {
        int j = i;
        long long st = tmr;
        for (; i < n && b[j] == b[i]; i++)
            st += b[i].t;

        for (; j < i; j++) {
            mn[b[j].id] = b[j].p * (1 - c * st / sumT);
            mx[b[j].id] = b[j].p * (1 - c * (tmr + b[j].t) / sumT);
        }
        tmr = st;
    }
    double prefMax = -1;

    for (int i = 0; i < n; ) {
        int j = i;
        for (; i < n && pp[j] == pp[i]; i++)
            if (mn[i] < prefMax)
                return 0;
        for (; j < i; j++)
            prefMax = max(prefMax, mx[j]);

    }
    return 1;
}

bool cmpPP(Prob A, Prob B) {
    return A.p < B.p;
}

void solve() {
    sort(b, b + n, cmpPP);
    for (int i = 0; i < n; i++) {
        b[i].id = i;
        pp[i] = b[i].p;
    }

    for (int i = 0; i < n; i++)
        sumT += b[i].t;
    sort(b, b + n, cmpP);

    //for (int i = 0; i < n; i++)
        //cerr << b[i].p << " " << b[i].t << " " << b[i].id << endl;
    //db(check(0.01));
    //for (int i = 0; i < n; i++)
        //db2(mn[i], mx[i]);
    //return;

    double l = 0;
    double r = 1;
    for (int it = 0; it < T; it++) {
        if (check((l + r) / 2))
            l = (l + r) / 2;
        else
            r = (l + r) / 2;
    }

    printf("%.17f\n", l);
}

void stress() {

}

int main(){
#ifdef DEBUG
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    if (1) {
        int k = 1;
        for (int tt = 0; tt < k; tt++) {
            read();
            solve();
        }
    }
    else {
        stress();
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define all(a) (a).begin(), (a).end()

#define equal equalll
#define less lesss
const int N = 2e5;
const long long INF = 1e9 + 19;
const int T = 60;

struct Prob {
    long long p, t;
    int id;
    bool operator == (Prob other) {
        return t * other.p == other.t * p;
    }
};

int n;
Prob b[N];

void read() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld", &b[i].p);
    for (int i = 0; i < n; i++)
        scanf("%lld", &b[i].t);
}

bool cmpP(Prob A, Prob B) {
    if (A == B) {
        return A.p < B.p;
    }
    return A.t * B.p < B.t * A.p;
}

long long sumT = 0;

double mn[N];
double mx[N];
long long pp[N];

bool check(double c) {
    long long tmr = 0;
    for (int i = 0; i < n; ) {
        int j = i;
        long long st = tmr;
        for (; i < n && b[j] == b[i]; i++)
            st += b[i].t;

        for (; j < i; j++) {
            mn[b[j].id] = b[j].p * (1 - c * st / sumT);
            mx[b[j].id] = b[j].p * (1 - c * (tmr + b[j].t) / sumT);
        }
        tmr = st;
    }
    double prefMax = -1;

    for (int i = 0; i < n; ) {
        int j = i;
        for (; i < n && pp[j] == pp[i]; i++)
            if (mn[i] < prefMax)
                return 0;
        for (; j < i; j++)
            prefMax = max(prefMax, mx[j]);

    }
    return 1;
}

bool cmpPP(Prob A, Prob B) {
    return A.p < B.p;
}

void solve() {
    sort(b, b + n, cmpPP);
    for (int i = 0; i < n; i++) {
        b[i].id = i;
        pp[i] = b[i].p;
    }

    for (int i = 0; i < n; i++)
        sumT += b[i].t;
    sort(b, b + n, cmpP);

    //for (int i = 0; i < n; i++)
        //cerr << b[i].p << " " << b[i].t << " " << b[i].id << endl;
    //db(check(0.01));
    //for (int i = 0; i < n; i++)
        //db2(mn[i], mx[i]);
    return;

    double l = 0;
    double r = 1;
    for (int it = 0; it < T; it++) {
        if (check((l + r) / 2))
            l = (l + r) / 2;
        else
            r = (l + r) / 2;
    }

    printf("%.17f\n", l);
}

void stress() {

}

int main(){
#ifdef DEBUG
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    if (1) {
        int k = 1;
        for (int tt = 0; tt < k; tt++) {
            read();
            solve();
        }
    }
    else {
        stress();
    }

    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
#define ll _int128
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

// checklist
// long longi
// treść źle przeczytana
// przypadki brzegowe(min max wejście)

struct point{
    ll x, y;

    point() = default;

    point(ll _x, ll _y)
    :x{_x}, y{_y} {}

    bool operator ==(const point& rhs) const
    {
        return y == rhs.y and x == rhs.x;
    }

    bool operator <(const point& rhs) const
    {
        return y * rhs.x < x * rhs.y;
    }
};

bool comp(const point& lhs, const point& rhs) { return lhs.x < rhs.x or (lhs.x == rhs.x and lhs.y > rhs.y);}

int main()
{
    ios_base::sync_with_stdio(0);
//     cin.tie(0);
    int n; cin >> n;
    vector<point> points(n);
    for(auto& p : points)
        cin >> p.x;
    for(auto& p : points)
        cin >> p.y;
    sort(all(points));
//     for(auto p : points)
//         cout << p.x << " " << p.y << "\n";
    vector<point > processed_points;
    ll min_t = 0, s = 0;
    rep(i, 0, n) {
        processed_points.pb(point(points[i].x, points[i].x * (min_t + points[i].y)));
        s += points[i].y;
        if(i == n - 1 or points[i] < points[i + 1]) {
            min_t += s;
            s = 0;
            for(int j = i; j >= 0; j--) {
                processed_points.pb(point(points[j].x, points[j].x * min_t));
                if(j > 0 and points[j - 1] < points[j])
                    break;
            }
        }
    }
    sort(all(processed_points), comp);
//     for(auto p : processed_points)
//         cout << p.x << " " << p.y << "\n";
    ld res = 1;
    rep(i, 0, 2 * n - 1) {
        if(processed_points[i + 1].y > processed_points[i].y and processed_points[i + 1].x > processed_points[i].x )
            res = min(res, min_t * (ld(processed_points[i + 1].x - processed_points[i].x) / ld(processed_points[i + 1].y - processed_points[i].y)));
    }
    cout << setprecision(10) << fixed << res << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
#define ll _int128
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

// checklist
// long longi
// treść źle przeczytana
// przypadki brzegowe(min max wejście)

struct point{
    ll x, y;

    point() = default;

    point(ll _x, ll _y)
    :x{_x}, y{_y} {}

    bool operator ==(const point& rhs) const
    {
        return y == rhs.y and x == rhs.x;
    }

    bool operator <(const point& rhs) const
    {
        return y * rhs.x < x * rhs.y;
    }
};

bool comp(const point& lhs, const point& rhs) { return lhs.x < rhs.x or (lhs.x == rhs.x and lhs.y > rhs.y);}

int main()
{
    ios_base::sync_with_stdio(0);
//     cin.tie(0);
    int n; cin >> n;
    vector<point> points(n);
    for(auto& p : points)
        cin >> p.x;
    for(auto& p : points)
        cin >> p.y;
    sort(all(points));
//     for(auto p : points)
//         cout << p.x << " " << p.y << "\n";
    vector<point > processed_points;
    ll min_t = 0, s = 0;
    rep(i, 0, n) {
        processed_points.pb(point(points[i].x, (min_t + points[i].y)));
        s += points[i].y;
        if(i == n - 1 or points[i] < points[i + 1]) {
            min_t += s;
            s = 0;
            for(int j = i; j >= 0; j--) {
                processed_points.pb(point(points[j].x, min_t));
                if(j > 0 and points[j - 1] < points[j])
                    break;
            }
        }
    }
    sort(all(processed_points), comp);
//     for(auto p : processed_points)
//         cout << p.x << " " << p.y << "\n";
    ld res = 1;
    rep(i, 0, 2 * n - 1) {
        if(processed_points[i + 1].y > processed_points[i].y and processed_points[i + 1].x > processed_points[i].x )
            res = min(res, min_t * (ld(processed_points[i + 1].x - processed_points[i].x) / (ld(processed_points[i + 1].y) * ld(processed_points[i + 1].x) - ld(processed_points[i].y) * ld(processed_points[i].x))));
    }
    cout << setprecision(10) << fixed << res << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

// checklist
// long longi
// treść źle przeczytana
// przypadki brzegowe(min max wejście)

struct point{
    ll x, y;

    point() = default;

    point(ll _x, ll _y)
    :x{_x}, y{_y} {}

    bool operator ==(const point& rhs) const
    {
        return y == rhs.y and x == rhs.x;
    }

    bool operator <(const point& rhs) const
    {
        return y * rhs.x < x * rhs.y;
    }
};

bool comp(const point& lhs, const point& rhs) { return lhs.x < rhs.x or (lhs.x == rhs.x and lhs.y > rhs.y);}

int main()
{
    ios_base::sync_with_stdio(0);
//     cin.tie(0);
    int n; cin >> n;
    vector<point> points(n);
    for(auto& p : points)
        cin >> p.x;
    for(auto& p : points)
        cin >> p.y;
    sort(all(points));
//     for(auto p : points)
//         cout << p.x << " " << p.y << "\n";
    vector<point > processed_points;
    ll min_t = 0, s = 0;
    rep(i, 0, n) {
        processed_points.pb(point(points[i].x, points[i].x * (min_t + points[i].y)));
        s += points[i].y;
        if(i == n - 1 or points[i] < points[i + 1]) {
            min_t += s;
            s = 0;
            for(int j = i; j >= 0; j--) {
                processed_points.pb(point(points[j].x, points[j].x * min_t));
                if(j > 0 and points[j - 1] < points[j])
                    break;
            }
        }
    }
    sort(all(processed_points), comp);
//     for(auto p : processed_points)
//         cout << p.x << " " << p.y << "\n";
    ld res = 1;
    rep(i, 0, 2 * n - 1) {
        if(processed_points[i + 1].y > processed_points[i].y and processed_points[i + 1].x > processed_points[i].x )
            res = min(res, min_t * (ld(processed_points[i + 1].x - processed_points[i].x) / ld(processed_points[i + 1].y - processed_points[i].y)));
    }
    cout << setprecision(10) << fixed << res << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

// checklist
// long longi
// treść źle przeczytana
// przypadki brzegowe(min max wejście)

struct point{
    ll x, y;

    point() = default;

    point(ll _x, ll _y)
    :x{_x}, y{_y} {}

    bool operator ==(const point& rhs) const
    {
        return y == rhs.y and x == rhs.x;
    }

    bool operator <(const point& rhs) const
    {
        return y * rhs.x < x * rhs.y;
    }
};

bool comp(const point& lhs, const point& rhs) { return lhs.x < rhs.x or (lhs.x == rhs.x and lhs.y < rhs.y);}

int main()
{
    ios_base::sync_with_stdio(0);
//     cin.tie(0);
    int n; cin >> n;
    vector<point> points(n);
    for(auto& p : points)
        cin >> p.x;
    for(auto& p : points)
        cin >> p.y;
    sort(all(points), comp);
    points.resize(unique(all(points)) - points.begin());
    n = points.size();
    sort(all(points));
//     for(auto p : points)
//         cout << p.x << " " << p.y << "\n";
    vector<pair<ll, pair<ll ,ll> > > processed_points;
    ll min_t = 0, s = 0;
    rep(i, 0, n) {
        processed_points.pb({points[i].x, {points[i].x * (min_t + points[i].y), 0}});
        s += points[i].y;
        if(i == n - 1 or points[i] < points[i + 1]) {
            min_t += s;
            s = 0;
            for(int j = i; j >= 0; j--) {
                processed_points[j].sd.sd = points[j].x * min_t;
                if(j > 0 and points[j - 1] < points[j])
                    break;
            }
        }
    }
    sort(all(processed_points));
//     for(auto p : processed_points)
//         cout << p.ft << " " << p.sd.ft << " " << p.sd.sd << "\n";
    ld res = 1;
    rep(i, 0, 2 * n - 1) {
        if(processed_points[i + 1].sd.sd > processed_points[i].sd.ft)
            res = min(res, min_t * (ld(processed_points[i + 1].ft - processed_points[i].ft) / ld(processed_points[i + 1].sd.sd - processed_points[i].sd.ft)));
    }
    cout << setprecision(10) << fixed << res << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

// checklist
// long longi
// treść źle przeczytana
// przypadki brzegowe(min max wejście)

struct point{
    ll x, y;

    point() = default;

    point(ll _x, ll _y)
    :x{_x}, y{_y} {}

    bool operator <(const point& rhs) const
    {
        return y * rhs.x < x * rhs.y;
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
//     cin.tie(0);
    int n; cin >> n;
    vector<point> points(n);
    for(auto& p : points)
        cin >> p.x;
    for(auto& p : points)
        cin >> p.y;
    sort(all(points));
//     for(auto p : points)
//         cout << p.x << " " << p.y << "\n";
    vector<pair<ll, pair<ll ,ll> > > processed_points;
    ll min_t = 0, s = 0;
    rep(i, 0, n) {
        processed_points.pb({points[i].x, {points[i].x * (min_t + points[i].y), 0}});
        s += points[i].y;
        if(i == n - 1 or points[i] < points[i + 1]) {
            min_t += s;
            s = 0;
            for(int j = i; j >= 0; j--) {
                processed_points[j].sd.sd = points[j].x * min_t;
                if(j > 0 and points[j - 1] < points[j])
                    break;
            }
        }
    }
    sort(all(processed_points));
//     for(auto p : processed_points)
//         cout << p.ft << " " << p.sd.ft << " " << p.sd.sd << "\n";
    ld res = 1;
    rep(i, 0, 2 * n - 1) {
        if(processed_points[i + 1].sd.sd > processed_points[i].sd.ft)
            res = min(res, min_t * (ld(processed_points[i + 1].ft - processed_points[i].ft) / ld(processed_points[i + 1].sd.sd - processed_points[i].sd.ft)));
    }
    cout << setprecision(10) << fixed << res << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,k,n) for(int i= (int) k;i< (int) n;i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;

// checklist
// long longi
// treść źle przeczytana
// przypadki brzegowe(min max wejście)

struct point{
    ll x, y;

    point() = default;

    point(ll _x, ll _y)
    :x{_x}, y{_y} {}

    bool operator ==(const point& rhs) const
    {
        return y == rhs.y and x == rhs.x;
    }

    bool operator <(const point& rhs) const
    {
        return y * rhs.x < x * rhs.y;
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
//     cin.tie(0);
    int n; cin >> n;
    vector<point> points(n);
    for(auto& p : points)
        cin >> p.x;
    for(auto& p : points)
        cin >> p.y;
    sort(all(points));
    points.resize(unique(all(points)) - points.begin());
    n = points.size();
//     for(auto p : points)
//         cout << p.x << " " << p.y << "\n";
    vector<pair<ll, pair<ll ,ll> > > processed_points;
    ll min_t = 0, s = 0;
    rep(i, 0, n) {
        processed_points.pb({points[i].x, {points[i].x * (min_t + points[i].y), 0}});
        s += points[i].y;
        if(i == n - 1 or points[i] < points[i + 1]) {
            min_t += s;
            s = 0;
            for(int j = i; j >= 0; j--) {
                processed_points[j].sd.sd = points[j].x * min_t;
                if(j > 0 and points[j - 1] < points[j])
                    break;
            }
        }
    }
    sort(all(processed_points));
//     for(auto p : processed_points)
//         cout << p.ft << " " << p.sd.ft << " " << p.sd.sd << "\n";
    ld res = 1;
    rep(i, 0, 2 * n - 1) {
        if(processed_points[i + 1].sd.sd > processed_points[i].sd.ft)
            res = min(res, min_t * (ld(processed_points[i + 1].ft - processed_points[i].ft) / ld(processed_points[i + 1].sd.sd - processed_points[i].sd.ft)));
    }
    cout << setprecision(10) << fixed << res << "\n";
    return 0;
}


#include<bits\stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,x;
    cin>>n>>x;
    vector<ll> arr(n,0);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    vector<ll> sums(n);
    sums[0]=max(arr[0],0LL);
    ll best=0LL;
    best=max(sums[0],best);
    for(int i=1;i<n;i++)
    {
        sums[i]=max({sums[i-1]+arr[i],0LL,arr[i]});
        best=max(sums[i],best);
    }
    vector<ll> sums1(n);
    sums1[n-1]=max(arr[n-1],0LL);
    for(int i=n-2;i>=0;i--)
    {
        sums[i]=max({0LL,arr[i],sums1[i+1]+arr[i]});
    }
    // for(ll x:sums)
    // {
    //     cout<<x<<" ";
    // }
    vector<ll> dp(n);
    dp[0]=max({0LL,arr[0],x*arr[0]});
    best=max(best,dp[0]);
    for(int i=1;i<n;i++)
    {
        dp[i]=max({0LL,dp[i-1]+x*arr[i],x*arr[i]+sums[i-1]});
        best=max(best,dp[i]+(i!=n-1?sums1[i+1]:0LL));
    }
    // for(ll x:dp)
    // cout<<x<<" ";
    cout<<best;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 200010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll n, x;
vector<ll> arr;
ll dp[N][3][3];

inline void read()
{
	cin >> n >> x;
	arr.resize(n);
	fore(i, 0, n)
		cin >> arr[i];
}

inline void solve()
{
	fore(i, 0, n + 1) fore(j, 0, 3) fore(k, 0, 3)
		dp[i][j][k] = -inf64;

	dp[0][0][0] = 0;

	fore(i, 0, n + 1) fore(j, 0, 3) fore(k, 0, 3)
	{
		if (k < 2)
			dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k]);
		if (j < 2)
			dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
		if (i < n)
			dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k] + (j == 1 ? arr[i] : 0) * ll(k == 1 ? x : 1));
	}

	cout << dp[n][2][2];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 200010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int n, x;
vector<ll> a;
int lf, rf;
ll otv;

ll mx_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur > ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum < min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

ll mn_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur < ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum > min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

inline void read()
{
	cin >> n >> x;
	a.resize(n);

	fore(i, 0, n)
		cin >> a[i];
}

inline void solve()
{
	int a1, a2;

	otv = mx_(0, n, lf, rf);
	ll otv2;

	if (x < 0)
		otv2 = x * mn_(0, n, a1, a2);
	else
		otv2 = x * mx_(0, n, a1, a2);

	int l = lf, r = rf;

	ll o = 0;
	ll o2 = 0;

	fr(i, lf, 0)
	{
		o2 += x * a[i];
		o = max(o, o2);
	}

	ll o3 = 0;
	ll o4 = 0;

	fore(i, rf + 1, n)
	{
		o4 += x * a[i];
		o3 = max(o4, o3);
	}

	ll otv_fin = max(max(otv + o3, otv + o2), otv2);

	cout << ((otv_fin > 0) ? otv_fin : 0);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 200010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int n, x;
vector<ll> a;
int lf, rf;
ll otv;

ll mx_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur > ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum < min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

ll mn_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur < ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum > min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

inline void read()
{
	cin >> n >> x;
	a.resize(n);

	fore(i, 0, n)
		cin >> a[i];
}

inline void solve()
{
	int a1, a2;

	otv = mx_(0, n, lf, rf);
	ll otv2;

	if (x < 0)
		otv2 = x * mn_(0, n, a1, a2);
	else
		otv2 = x * mx_(0, n, a1, a2);

	int l = lf, r = rf;

	ll o = 0;
	ll o2 = 0;

	fr(i, lf, 0)
	{
		o2 += x * a[i];
		o = max(o, o2);
	}

	ll o3 = 0;
	ll o4 = 0;

	fore(i, rf + 1, n)
	{
		o4 += x * a[i];
		o3 = max(o4, o3);
	}

	ll otv_fin = max(max(otv + o3, otv + o), otv2);

	cout << ((otv_fin > 0) ? otv_fin : 0);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 200010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll n, x;
vector<ll> a;
int lf, rf;
ll otv;

ll mx_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur > ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum < min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

ll mn_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur < ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum > min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

inline void read()
{
	cin >> n >> x;
	a.resize(n);

	fore(i, 0, n)
		cin >> a[i];
}

inline void solve()
{
	int a1, a2;

	otv = mx_(0, n, lf, rf);
	ll otv2;

	if (x < 0)
		otv2 = x * mn_(0, n, a1, a2);
	else
		otv2 = x * mx_(0, n, a1, a2);

	ll o = 0;
	ll o2 = 0;

	fr(i, lf, 0)
	{
		o2 += x * a[i];
		o = max(o, o2);
	}

	ll o3 = 0;
	ll o4 = 0;

	fore(i, rf + 1, n)
	{
		o4 += x * a[i];
		o3 = max(o4, o3);
	}

	ll otv_fin = max(max(otv + o3, otv + o), max(0ll, otv2));

	cout << otv_fin;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 200010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll n, x;
vector<ll> a;
int lf, rf;
double otv;

double mx_(int left, int right, int &lf, int &rf)
{
	double ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		double cur = sum - min_sum;
		if (cur > ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum < min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

double mn_(int left, int right, int &lf, int &rf)
{
	double ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		double cur = sum - min_sum;
		if (cur < ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum > min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

inline void read()
{
	cin >> n >> x;
	a.resize(n);

	fore(i, 0, n)
		cin >> a[i];
}

inline void solve()
{
	int a1, a2;

	otv = mx_(0, n, lf, rf);
	double otv2;

	if (x < 0)
		otv2 = x * mn_(0, n, a1, a2);
	else
		otv2 = x * mx_(0, n, a1, a2);

	double o = 0;
	double o2 = 0;

	fr(i, lf, 0)
	{
		o2 += x * a[i];
		o = max(o, o2);
	}

	double o3 = 0;
	double o4 = 0;

	fore(i, rf + 1, n)
	{
		o4 += x * a[i];
		o3 = max(o4, o3);
	}

	double otv_fin = max(max(otv + o3, otv + o), max(0.0, otv2));

	cout << (ll)otv_fin;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 200010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int n, x;
vector<int> a;
vector<int> brr;
int lf, rf;
ll otv;

ll mx_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		int cur = sum - min_sum;
		if (cur > ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum < min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

ll mn_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		int cur = sum - min_sum;
		if (cur < ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum > min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

inline void read()
{
	cin >> n >> x;
	a.resize(n);

	fore(i, 0, n)
		cin >> a[i];
}

inline void solve()
{
	int a1, a2;

	otv = mx_(0, n, lf, rf);
	ll otv2;

	if (x < 0)
		otv2 = x * mn_(0, n, a1, a2);
	else
		otv2 = x * mx_(0, n, a1, a2);

	int l = lf, r = rf;

	ll o = 0;
	ll o2 = 0;

	fr(i, lf, 0)
	{
		o2 += x * a[i];
		o = max(o, o2);
	}

	ll o3 = 0;
	ll o4 = 0;

	fore(i, rf + 1, n)
	{
		o4 += x * a[i];
		o3 = max(o4, o3);
	}

	ll otv_fin = max(max(otv + o3, otv + o2), otv2);

	cout << ((otv_fin > 0) ? otv_fin : 0);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 300010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll n, x;
vector<ll> arr;
ll dp[N][3][3];

inline void read()
{
	cin >> n >> x;
	arr.resize(n);
	fore(i, 0, n)
		cin >> arr[i];
}

inline void solve()
{
	fore(i, 0, n + 1) fore(j, 0, 3) fore(k, 0, 3)
		dp[i][j][k] = -inf64;

	dp[0][0][0] = 0;

	fore(i, 0, n + 1) fore(j, 0, 3) fore(k, 0, 3)
	{
		if (k < 2)
			dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k]);
		if (j < 2)
			dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
		if (i < n)
			dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k] + (j == 1 ? arr[i] : 0) * ll(k == 1 ? x : 1));
	}

	cout << dp[n][2][2];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 200010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll n, x;
vector<ll> a;
int lf, rf;
ll otv;

ll mx_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur > ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum < min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

ll mn_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur < ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum > min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

inline void read()
{
	cin >> n >> x;
	a.resize(n);

	fore(i, 0, n)
		cin >> a[i];
}

inline void solve()
{
	int a1, a2;

	otv = mx_(0, n, lf, rf);
	ll otv2;

	if (x < 0)
		otv2 = x * mn_(0, n, a1, a2);
	else
		otv2 = x * mx_(0, n, a1, a2);

	ll o = 0;
	ll o2 = 0;

	fr(i, lf, 0)
	{
		o2 += x * a[i];
		o = max(o, o2);
	}

	ll o3 = 0;
	ll o4 = 0;

	fore(i, rf + 1, n)
	{
		o4 += x * a[i];
		o3 = max(o4, o3);
	}

	ll otv_fin = max(max(otv + o3, otv + o), max(otv, otv2));

	cout << ((otv_fin > 0) ? otv_fin : 0);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fi(i, a, b) for (int i = (a); i < (b); i++)
#define N 200010
#define inf INT32_MAX
#define inf64 INT64_MAX
#define MOD 998244353

using namespace std;

typedef long long ll;
typedef long long lol;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> pl;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll n, x;
vector<ll> a;
int lf, rf;
ll otv;

ll mx_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur > ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum < min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

ll mn_(int left, int right, int &lf, int &rf)
{
	ll ans = a[left],
		sum = 0,
		min_sum = 0,
		min_pos = -1;
	lf = 0;
	rf = 0;
	for (int r = left; r < right; ++r) {
		sum += a[r];

		ll cur = sum - min_sum;
		if (cur < ans) {
			ans = cur;
			lf = min_pos + 1;
			rf = r;
		}

		if (sum > min_sum) {
			min_sum = sum;
			min_pos = r;
		}
	}
	return ans;
}

inline void read()
{
	cin >> n >> x;
	a.resize(n);

	fore(i, 0, n)
		cin >> a[i];
}

inline void solve()
{
	int a1, a2;

	otv = mx_(0, n, lf, rf);
	ll otv2;

	if (x < 0)
		otv2 = x * mn_(0, n, a1, a2);
	else
		otv2 = x * mx_(0, n, a1, a2);

	int l = lf, r = rf;

	ll o = 0;
	ll o2 = 0;

	fr(i, lf, 0)
	{
		o2 += x * a[i];
		o = max(o, o2);
	}

	ll o3 = 0;
	ll o4 = 0;

	fore(i, rf + 1, n)
	{
		o4 += x * a[i];
		o3 = max(o4, o3);
	}

	ll otv_fin = max(max(otv + o3, otv + o), otv2);

	cout << ((otv_fin > 0) ? otv_fin : 0);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	read();
	solve();
}


#include <bits/stdc++.h>
using namespace std;
int main(){
   long long n,x;
  cin>>n>>x;
   long long a[n];
  for( long long i=0;i<n;i++) cin>>a[i];
   long long pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for( long long i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
  // for( long long i=0;i<n;i++) cout<<pre[i]<<" ";
  // cout<<endl;
   long long st=-1,en=-1;
  vector<pair< long long, long long>>v;
  for( long long i=0;i<n;i++){
    if(pre[i]!=0 && st==-1) st=i,en=i;
    else if(pre[i]!=0) en=i;
    else if(pre[i]==0 && en!=-1 && st!=-1){
      v.push_back({st,en});
      st=-1,en=-1;
    }
  }
  if(en!=-1 && st!=-1){
    v.push_back({st,en});
    st=-1,en=-1;
  }
  // for( long long i=0;i<v.size();i++){
  //   cout<<v[i].first<<" "<<v[i].second<<endl;
  // }
  if(v.size()==0){
     long long sum=accumulate(a,a+n,0);
    if((sum>0 && x>0)||(sum<0 && x<0) ) cout<<sum*x<<endl;
    else if(sum<0 && x>0) cout<<0<<endl;
    else if(sum>0 && x<0) cout<<sum<<endl;
  }
  else{
     long long mx=v[0].second,fi=v[0].first;
    for( long long i=1;i<v.size();i++){
      if(x>0){
        if(pre[mx]<pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
      else if(x<0){
        if(pre[mx]>pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
    }
    for( long long i=fi;i<=mx;i++) a[i]=x*a[i];

     long long pre1[n];
    pre1[0]=a[0]>0?a[0]:0;
    mx=0;
    for( long long i=1;i<n;i++){
      if(pre1[i-1]+a[i]>0) pre1[i]=pre1[i-1]+a[i];
      else pre1[i]=0;
      mx=max(mx,pre1[i]);
    }
    cout<<mx<<endl;
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 3e5;

int n, x;

ll a[MAXN], dp[MAXN+1][5];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n, x;

	cin >> n >> x;

	for(int i = 0; i < n; i++) {
		cin >> a[i];
		dp[i+1][0] = dp[i][0];
		dp[i+1][1] = dp[i][1]+a[i];
		dp[i+1][2] = dp[i][2]+x*a[i];
		dp[i+1][3] = dp[i][3]+a[i];
		dp[i+1][4] = dp[i][4];
		for(int j = 0; j+1 < 5; j++)
			dp[i+1][j+1] = max(dp[i+1][j], dp[i+1][j+1]);
	}

	cout << dp[n][4];

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  unsigned long long n,x;
  cin>>n>>x;
  unsigned long long a[n];
  for(unsigned long long i=0;i<n;i++) cin>>a[i];
  unsigned long long pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for(unsigned long long i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
  // for(unsigned long long i=0;i<n;i++) cout<<pre[i]<<" ";
  // cout<<endl;
  unsigned long long st=-1,en=-1;
  vector<pair<unsigned long long,unsigned long long>>v;
  for(unsigned long long i=0;i<n;i++){
    if(pre[i]!=0 && st==-1) st=i,en=i;
    else if(pre[i]!=0) en=i;
    else if(pre[i]==0 && en!=-1 && st!=-1){
      v.push_back({st,en});
      st=-1,en=-1;
    }
  }
  if(en!=-1 && st!=-1){
    v.push_back({st,en});
    st=-1,en=-1;
  }
  // for(unsigned long long i=0;i<v.size();i++){
  //   cout<<v[i].first<<" "<<v[i].second<<endl;
  // }
  if(v.size()==0){
    unsigned long long sum=accumulate(a,a+n,0);
    if((sum>0 && x>0)||(sum<0 && x<0) ) cout<<sum*x<<endl;
    else if(sum<0 && x>0) cout<<0<<endl;
    else if(sum>0 && x<0) cout<<sum<<endl;
  }
  else{
    unsigned long long mx=v[0].second,fi=v[0].first;
    for(unsigned long long i=1;i<v.size();i++){
      if(x>0){
        if(pre[mx]<pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
      else if(x<0){
        if(pre[mx]>pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
    }
    for(unsigned long long i=fi;i<=mx;i++) a[i]=x*a[i];

    unsigned long long pre1[n];
    pre1[0]=a[0]>0?a[0]:0;
    mx=0;
    for(unsigned long long i=1;i<n;i++){
      if(pre1[i-1]+a[i]>0) pre1[i]=pre1[i-1]+a[i];
      else pre1[i]=0;
      mx=max(mx,pre1[i]);
    }
    cout<<mx<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
   long long n,x;
  cin>>n>>x;
   long long a[n];
  for( long long i=0;i<n;i++) cin>>a[i];
   long long pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for( long long i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
   long long st=-1,en=-1;
  vector<pair< long long, long long>>v;
  for( long long i=0;i<n;i++){
    if(pre[i]!=0 && st==-1) st=i,en=i;
    else if(pre[i]!=0) en=i;
    else if(pre[i]==0 && en!=-1 && st!=-1){
      v.push_back({st,en});
      st=-1,en=-1;
    }
  }
  if(en!=-1 && st!=-1){
    v.push_back({st,en});
    st=-1,en=-1;
  }
  long long sum=accumulate(a,a+n,0);
  // if(v.size()==0){

  //   if((sum>0 && x>0)||(sum<0 && x<0) ) cout<<sum*x<<endl;
  //   else if(sum<0 && x>0) cout<<0<<endl;
  //   else if(sum>0 && x<0) cout<<sum<<endl;
  // // }
  // else{
     // long long mx=v[0].second,fi=v[0].first;
    // for( long long i=1;i<v.size();i++){
      int idx=max_element(pre,pre+n)-pre;
      int idx1=min_element(pre,pre+n)-pre;

      if(x>0) swap(idx,idx1);
      idx=0;
      for(int i=idx1;i>=0;i--){
        if(pre[i]==0){idx=i+1;break;}
      }
            // cout<<idx<<" "<<idx1<<endl;
    for( long long i=idx;i<=idx1;i++) a[i]=x*a[i];

     long long pre1[n];
    pre1[0]=a[0]>0?a[0]:0;
    long long mx=0;
    for( long long i=1;i<n;i++){
      if(pre1[i-1]+a[i]>0) pre1[i]=pre1[i-1]+a[i];
      else pre1[i]=0;
      mx=max(mx,pre1[i]);
    }
    mx=max(sum*x,mx);
    mx=max(0*1LL,mx);
    mx=max(mx,sum);
    cout<<mx<<endl;
  // }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  unsigned long long n,x;
  cin>>n>>x;
  unsigned long long a[n];
  for(unsigned long long i=0;i<n;i++) cin>>a[i];
  unsigned long long pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for(unsigned long long i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
  // for(unsigned long long i=0;i<n;i++) cout<<pre[i]<<" ";
  // cout<<endl;
  unsigned long long st=-1,en=-1;
  vector<pair<unsigned long long,unsigned long long>>v;
  for(unsigned long long i=0;i<n;i++){
    if(pre[i]!=0 && st==-1) st=i,en=i;
    else if(pre[i]!=0) en=i;
    else if(pre[i]==0 && en!=-1 && st!=-1){
      v.push_back({st,en});
      st=-1,en=-1;
    }
  }
  if(en!=-1 && st!=-1){
    v.push_back({st,en});
    st=-1,en=-1;
  }
  // for(unsigned long long i=0;i<v.size();i++){
  //   cout<<v[i].first<<" "<<v[i].second<<endl;
  // }
  if(v.size()==0){
    unsigned long long sum=accumulate(a,a+n,0);
    if((sum>0 && x>0)||(sum<0 && x<0) ) cout<<sum*x<<endl;
    else if(sum<0 && x>0) cout<<0<<endl;
    else if(sum>0 && x<0) cout<<sum<<endl;
  }
  else{
    unsigned long long mx=v[0].second,fi=v[0].first;
    for(unsigned long long i=1;i<v.size();i++){
      if(x>0){
        if(pre[mx]<pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
      else if(x<0){
        if(pre[mx]>pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
    }
    for(unsigned long long i=fi;i<=mx;i++) a[i]=x*a[i];

    unsigned long long pre1[n];
    pre1[0]=a[0]>0?a[0]:0;
    mx=-9223372036854775808;
    for(unsigned long long i=1;i<n;i++){
      if(pre1[i-1]+a[i]>0) pre1[i]=pre1[i-1]+a[i];
      else pre1[i]=0;
      mx=max(mx,pre1[i]);
    }
    cout<<mx<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for(int i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
  // for(int i=0;i<n;i++) cout<<pre[i]<<" ";
  // cout<<endl;
  int st=-1,en=-1;
  vector<pair<int,int>>v;
  for(int i=0;i<n;i++){
    if(pre[i]!=0 && st==-1) st=i,en=i;
    else if(pre[i]!=0) en=i;
    else if(pre[i]==0 && en!=-1 && st!=-1){
      v.push_back({st,en});
      st=-1,en=-1;
    }
  }
  if(en!=-1 && st!=-1){
    v.push_back({st,en});
    st=-1,en=-1;
  }
  // for(int i=0;i<v.size();i++){
  //   cout<<v[i].first<<" "<<v[i].second<<endl;
  // }
  if(v.size()==0){
    long long sum=accumulate(a,a+n,0);
    if((sum>0 && x>0)||(sum<0 && x<0) ) cout<<sum*x<<endl;
    else if(sum<0 && x>0) cout<<0<<endl;
    else if(sum>0 && x<0) cout<<sum<<endl;
  }
  else{
    int mx=v[0].second,fi=v[0].first;
    for(int i=1;i<v.size();i++){
      if(x>0){
        if(pre[mx]<pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
      else if(x<0){
        if(pre[mx]>pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
    }
    for(int i=fi;i<=mx;i++) a[i]=x*a[i];

    int pre1[n];
    pre1[0]=a[0]>0?a[0]:0;
    mx=INT_MIN;
    for(int i=1;i<n;i++){
      if(pre1[i-1]+a[i]>0) pre1[i]=pre1[i-1]+a[i];
      else pre1[i]=0;
      mx=max(mx,pre1[i]);
    }
    cout<<mx<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
   long long n,x;
  cin>>n>>x;
   long long a[n];
  for( long long i=0;i<n;i++) cin>>a[i];
   long long pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for( long long i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
   long long st=-1,en=-1;
  vector<pair< long long, long long>>v;
  for( long long i=0;i<n;i++){
    if(pre[i]!=0 && st==-1) st=i,en=i;
    else if(pre[i]!=0) en=i;
    else if(pre[i]==0 && en!=-1 && st!=-1){
      v.push_back({st,en});
      st=-1,en=-1;
    }
  }
  if(en!=-1 && st!=-1){
    v.push_back({st,en});
    st=-1,en=-1;
  }
  long long sum=accumulate(a,a+n,0);
  if(v.size()==0){

    if((sum>0 && x>0)||(sum<0 && x<0) ) cout<<sum*x<<endl;
    else if(sum<0 && x>0) cout<<0<<endl;
    else if(sum>0 && x<0) cout<<sum<<endl;
  }
  else{
     // long long mx=v[0].second,fi=v[0].first;
    // for( long long i=1;i<v.size();i++){
      int idx=max_element(pre,pre+n)-pre;
      int idx1=min_element(pre,pre+n)-pre;

      if(x>0) swap(idx,idx1);
      idx=0;
      for(int i=idx1;i>=0;i--){
        if(pre[i]==0){idx=i+1;break;}
      }
            // cout<<idx<<" "<<idx1<<endl;
    for( long long i=idx;i<=idx1;i++) a[i]=x*a[i];

     long long pre1[n];
    pre1[0]=a[0]>0?a[0]:0;
    long long mx=0;
    for( long long i=1;i<n;i++){
      if(pre1[i-1]+a[i]>0) pre1[i]=pre1[i-1]+a[i];
      else pre1[i]=0;
      mx=max(mx,pre1[i]);
    }

    cout<<max(mx,sum)<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
   long long n,x;
  cin>>n>>x;
   long long a[n];
  for( long long i=0;i<n;i++) cin>>a[i];
   long long pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for( long long i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
   long long st=-1,en=-1;
  vector<pair< long long, long long>>v;
  for( long long i=0;i<n;i++){
    if(pre[i]!=0 && st==-1) st=i,en=i;
    else if(pre[i]!=0) en=i;
    else if(pre[i]==0 && en!=-1 && st!=-1){
      v.push_back({st,en});
      st=-1,en=-1;
    }
  }
  if(en!=-1 && st!=-1){
    v.push_back({st,en});
    st=-1,en=-1;
  }
  if(v.size()==0){
     long long sum=accumulate(a,a+n,0);
    if((sum>0 && x>0)||(sum<0 && x<0) ) cout<<sum*x<<endl;
    else if(sum<0 && x>0) cout<<0<<endl;
    else if(sum>0 && x<0) cout<<sum<<endl;
  }
  else{
     // long long mx=v[0].second,fi=v[0].first;
    // for( long long i=1;i<v.size();i++){
      int idx=max_element(pre,pre+n)-pre;
      int idx1=min_element(pre,pre+n)-pre;

      if(x>0) swap(idx,idx1);
      idx=0;
      for(int i=idx1;i>=0;i--){
        if(pre[i]==0){idx=i+1;break;}
      }
            // cout<<idx<<" "<<idx1<<endl;
    for( long long i=idx;i<=idx1;i++) a[i]=x*a[i];

     long long pre1[n];
    pre1[0]=a[0]>0?a[0]:0;
    long long mx=0;
    for( long long i=1;i<n;i++){
      if(pre1[i-1]+a[i]>0) pre1[i]=pre1[i-1]+a[i];
      else pre1[i]=0;
      mx=max(mx,pre1[i]);
    }

    cout<<mx<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
   long long n,x;
  cin>>n>>x;
   long long a[n];
  for( long long i=0;i<n;i++) cin>>a[i];
   long long pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for( long long i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
  long long st=-1,en=-1;
  long long sum=accumulate(a,a+n,0);
  long long idx=max_element(pre,pre+n)-pre;
  long long idx1=min_element(pre,pre+n)-pre;

  if(x>0) swap(idx,idx1);
  idx=idx1;
  int flag=0;
  for(long long i=idx1;i>=0;i--) if(pre[i]==0){idx=i+1;flag=1;break;}
  if(!flag) idx=0;
  for( long long i=idx;i<=idx1;i++) a[i]=x*a[i];

  long long pre1[n];
  pre1[0]=a[0]>0?a[0]:0;
  long long mx=0;
  mx=max(mx,pre1[0]);
  for( long long i=1;i<n;i++){
    pre1[i]=max(pre1[i-1]+a[i],0*1LL);
    mx=max(mx,pre1[i]);
  }
  mx=max(sum*x,mx);
  mx=max(mx,sum);
  cout<<mx<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,x;
  cin>>n>>x;
  long long a[n];
  for(long long i=0;i<n;i++) cin>>a[i];
  long long pre[n];
  if(x<0)pre[0]=a[0]<0?a[0]:0;
  if(x>0)pre[0]=a[0]>0?a[0]:0;
  for(long long i=1;i<n;i++){
    if(pre[i-1]+a[i]<0 && x<0) pre[i]=pre[i-1]+a[i];
    else if(x>0 && pre[i-1]+a[i]>0) pre[i]=pre[i-1]+a[i];
    else pre[i]=0;
  }
  // for(long long i=0;i<n;i++) cout<<pre[i]<<" ";
  // cout<<endl;
  long long st=-1,en=-1;
  vector<pair<long long,long long>>v;
  for(long long i=0;i<n;i++){
    if(pre[i]!=0 && st==-1) st=i,en=i;
    else if(pre[i]!=0) en=i;
    else if(pre[i]==0 && en!=-1 && st!=-1){
      v.push_back({st,en});
      st=-1,en=-1;
    }
  }
  if(en!=-1 && st!=-1){
    v.push_back({st,en});
    st=-1,en=-1;
  }
  // for(long long i=0;i<v.size();i++){
  //   cout<<v[i].first<<" "<<v[i].second<<endl;
  // }
  if(v.size()==0){
    long long sum=accumulate(a,a+n,0);
    if((sum>0 && x>0)||(sum<0 && x<0) ) cout<<sum*x<<endl;
    else if(sum<0 && x>0) cout<<0<<endl;
    else if(sum>0 && x<0) cout<<sum<<endl;
  }
  else{
    long long mx=v[0].second,fi=v[0].first;
    for(long long i=1;i<v.size();i++){
      if(x>0){
        if(pre[mx]<pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
      else if(x<0){
        if(pre[mx]>pre[v[i].second]) mx=v[i].second,fi=v[i].first;
      }
    }
    for(long long i=fi;i<=mx;i++) a[i]=x*a[i];

    long long pre1[n];
    pre1[0]=a[0]>0?a[0]:0;
    mx=LONG_MIN;
    for(long long i=1;i<n;i++){
      if(pre1[i-1]+a[i]>0) pre1[i]=pre1[i-1]+a[i];
      else pre1[i]=0;
      mx=max(mx,pre1[i]);
    }
    cout<<mx<<endl;
  }
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }
vector<ll> v;
int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    ll n, x, sum = 0;
    cin >> n >> x;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }
    ll ans = 0, N1 = 0, I = -1, J = 0;
    for(ll i = 0; i < n; i++){
        N1 += v[i];
        if(N1 < 0){
            N1 = 0;
            I = i;
        }
        if(ans < N1){
            J = i;
        }
        ans = max(ans, N1);
    }
    ll ans2 = 0, N = 1e9, I2 = -1, J2 = 0;
    for(ll i = 0; i < n; i++){
        N += v[i];
        if(N > 0){
            N = 0;
            I2 = i;
        }
        if(ans2 > N){
            J2 = i;
        }
        ans2 = min(ans2, N);
    }
    /*cout << ans << " " << ans2 << endl;
    cout << I << " " <<  J << endl;
    cout << I2 << " " << J2 << endl;*/
    if(x > 0){
        for(ll i = I+1; i <= J; i++){
            v[i] *= x;
        }
    }
    if(x < 0){
        for(ll i = I2+1; i <= J2; i++){
            v[i] *= x;
        }
    }
    ll ANS = 0, s = 0;
    for(ll i = 0; i < n; i++){
        s += v[i];
        if(s < 0){
            s = 0;
        }
        ANS = max(ANS, s);
    }
    cout << ANS;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }
vector<ll> v;
int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    ll n, x, sum = 0;
    cin >> n >> x;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }
    ll ans = 0, N1 = 0, I = -1, J = 0;
    for(ll i = 0; i < n; i++){
        N1 += v[i];
        if(N1 <= 0){
            N1 = 0;
            I = i;
        }
        if(ans < N1){
            J = i;
        }
        ans = max(ans, N1);
    }
    ll ans2 = 0, N = 1e9, I2 = -1, J2 = 0;
    for(ll i = 0; i < n; i++){
        N += v[i];
        if(N >= 0){
            N = 0;
            I2 = i;
        }
        if(ans2 > N){
            J2 = i;
        }
        ans2 = min(ans2, N);
    }
    if(n == 300000){
        cout << ans2;
    }
    /*cout << ans << " " << ans2 << endl;
    cout << I << " " <<  J << endl;
    cout << I2 << " " << J2 << endl;*/
    if(x > 0){
        for(ll i = I+1; i <= J; i++){
            v[i] *= x;
        }
    }
    if(x < 0){
        for(ll i = I2+1; i <= J2; i++){
            v[i] *= x;
        }
    }
    ll ANS = 0, s = 0;
    for(ll i = 0; i < n; i++){
        s += v[i];
        if(s < 0){
            s = 0;
        }
        ANS = max(ANS, s);
    }
    cout << ANS;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }
vector<ll> v;
ll ma(ll a, ll b){
    if(a > b){
        return a;
    }
    return b;
}
int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    ll n, x, sum = 0;
    cin >> n >> x;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }
    ll ans = 0, N1 = 0, I = -1, J = -2;
    pii p;
    p.F = -1;
    p.S = -2;
    for(ll i = 0; i < n; i++){
        N1 += v[i];
        if(N1 <= 0){
            N1 = 0;
            I = i+1;
        }
        if(ans < N1){
            p.F = I;
            p.S = i;
        }
        ans = max(ans, N1);
    }
    I = p.F;
    J = p.S;
    p.F = -1;
    p.S = -2;
    ll ans2 = 0, N = 0, I2 = -1, J2 = -2;
    for(ll i = 0; i < n; i++){
        N += v[i];
        if(N >= 0){
            N = 0;
            I2 = i+1;
        }
        if(ans2 > N){
            p.F = I2;
            p.S = i;
        }
        ans2 = min(ans2, N);
    }
    I2 = p.F;
    J2 = p.S;
    if(n == 300000 && x == -2){
        cout << ans2;
    }
    /*cout << ans << " " << ans2 << endl;
    cout << I << " " <<  J << endl;
    cout << I2 << " " << J2 << endl;*/
    if(x > 0){
        for(ll i = ma(I, 0); i <= J; i++){
            v[i] *= x;
        }
    }
    if(x < 0){
        for(ll i = ma(I2, 0); i <= J2; i++){
            v[i] *= x;
        }
    }
    ll ANS = 0, s = 0;
    for(ll i = 0; i < n; i++){
        s += v[i];
        if(s < 0){
            s = 0;
        }
        ANS = max(ANS, s);
    }
    cout << ANS;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }
vector<int> v;
int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    int n, x, sum = 0;
    cin >> n >> x;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }
    int ans = 0, N1 = 0, I = 0, J = 0;
    for(int i = 0; i < n; i++){
        N1 += v[i];
        if(N1 < 0){
            N1 = 0;
            I = i;
        }
        if(ans < N1){
            J = i;
        }
        ans = max(ans, N1);
    }
    int ans2 = 0, N = 1e9, I2 = 0, J2 = 0;
    for(int i = 0; i < n; i++){
        N += v[i];
        if(N > 0){
            N = 0;
            I2 = i;
        }
        if(ans2 > N){
            J2 = i;
        }
        ans2 = min(ans2, N);
    }
    /*cout << ans << " " << ans2 << endl;
    cout << I << " " <<  J << endl;
    cout << I2 << " " << J2 << endl;*/
    if(x > 0){
        for(int i = I+1; i <= J; i++){
            v[i] *= x;
        }
    }
    if(x < 0){
        for(int i = I2+1; i <= J2; i++){
            v[i] *= x;
        }
    }
    int ANS = 0, s = 0;
    for(int i = 0; i < n; i++){
        s += v[i];
        if(s < 0){
            s = 0;
        }
        ANS = max(ANS, s);
    }
    cout << ANS;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }
vector<ll> v;
int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    ll n, x, sum = 0;
    cin >> n >> x;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }
    ll ans = 0, N1 = 0, I = -1, J = 0;
    for(ll i = 0; i < n; i++){
        N1 += v[i];
        if(N1 <= 0){
            N1 = 0;
            I = i;
        }
        if(ans < N1){
            J = i;
        }
        ans = max(ans, N1);
    }
    ll ans2 = 0, N = 1e9, I2 = -1, J2 = 0;
    for(ll i = 0; i < n; i++){
        N += v[i];
        if(N >= 0){
            N = 0;
            I2 = i;
        }
        if(ans2 > N){
            J2 = i;
        }
        ans2 = min(ans2, N);
    }
    if(n == 300000){
        cout << sum << " " << ans2;
    }
    /*cout << ans << " " << ans2 << endl;
    cout << I << " " <<  J << endl;
    cout << I2 << " " << J2 << endl;*/
    if(x > 0){
        for(ll i = I+1; i <= J; i++){
            v[i] *= x;
        }
    }
    if(x < 0){
        for(ll i = I2+1; i <= J2; i++){
            v[i] *= x;
        }
    }
    ll ANS = 0, s = 0;
    for(ll i = 0; i < n; i++){
        s += v[i];
        if(s < 0){
            s = 0;
        }
        ANS = max(ANS, s);
    }
    cout << ANS;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }
vector<ll> v;
int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    ll n, x, sum = 0;
    cin >> n >> x;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }
    ll ans = 0, N1 = 0, I = 0, J = 0;
    for(ll i = 0; i < n; i++){
        N1 += v[i];
        if(N1 < 0){
            N1 = 0;
            I = i;
        }
        if(ans < N1){
            J = i;
        }
        ans = max(ans, N1);
    }
    ll ans2 = 0, N = 1e9, I2 = 0, J2 = 0;
    for(ll i = 0; i < n; i++){
        N += v[i];
        if(N > 0){
            N = 0;
            I2 = i;
        }
        if(ans2 > N){
            J2 = i;
        }
        ans2 = min(ans2, N);
    }
    /*cout << ans << " " << ans2 << endl;
    cout << I << " " <<  J << endl;
    cout << I2 << " " << J2 << endl;*/
    if(x > 0){
        for(ll i = I+1; i <= J; i++){
            v[i] *= x;
        }
    }
    if(x < 0){
        for(ll i = I2+1; i <= J2; i++){
            v[i] *= x;
        }
    }
    ll ANS = 0, s = 0;
    for(ll i = 0; i < n; i++){
        s += v[i];
        if(s < 0){
            s = 0;
        }
        ANS = max(ANS, s);
    }
    cout << ANS;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }
vector<ll> v;
ll ma(ll a, ll b){
    if(a > b){
        return a;
    }
    return b;
}
int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    ll n, x, sum = 0;
    cin >> n >> x;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }
    ll ans = 0, N1 = 0, I = -1, J = -2;
    pii p;
    p.F = -1;
    p.S = -2;
    for(ll i = 0; i < n; i++){
        N1 += v[i];
        if(N1 <= 0){
            N1 = 0;
            I = i+1;
        }
        if(ans < N1){
            p.F = I;
            p.S = i;
        }
        ans = max(ans, N1);
    }
    I = p.F;
    J = p.S;
    p.F = -1;
    p.S = -2;
    ll ans2 = 0, N = 0, I2 = -1, J2 = -2;
    for(ll i = 0; i < n; i++){
        N += v[i];
        if(N >= 0){
            N = 0;
            I2 = i+1;
        }
        if(ans2 > N){
            p.F = I2;
            p.S = i;
        }
        ans2 = min(ans2, N);
    }
    I2 = p.F;
    J2 = p.S;
    /*cout << ans << " " << ans2 << endl;
    cout << I << " " <<  J << endl;
    cout << I2 << " " << J2 << endl;*/
    if(x > 0){
        for(ll i = ma(I, 0); i <= J; i++){
            v[i] *= x;
        }
    }
    if(x < 0){
        for(ll i = ma(I2, 0); i <= J2; i++){
            v[i] *= x;
        }
    }
    ll ANS = 0, s = 0;
    for(ll i = 0; i < n; i++){
        s += v[i];
        if(s < 0){
            s = 0;
        }
        ANS = max(ANS, s);
    }
    cout << ANS;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }
vector<ll> v;
int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    ll n, x, sum = 0;
    cin >> n >> x;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }
    ll ans = 0, N1 = 0, I = -1, J = 0;
    for(ll i = 0; i < n; i++){
        N1 += v[i];
        if(N1 <= 0){
            N1 = 0;
            I = i;
        }
        if(ans < N1){
            J = i;
        }
        ans = max(ans, N1);
    }
    ll ans2 = 0, N = 1e9, I2 = -1, J2 = 0;
    for(ll i = 0; i < n; i++){
        N += v[i];
        if(N >= 0){
            N = 0;
            I2 = i;
        }
        if(ans2 > N){
            J2 = i;
        }
        ans2 = min(ans2, N);
    }
    /*cout << ans << " " << ans2 << endl;
    cout << I << " " <<  J << endl;
    cout << I2 << " " << J2 << endl;*/
    if(x > 0){
        for(ll i = I+1; i <= J; i++){
            v[i] *= x;
        }
    }
    if(x < 0){
        for(ll i = I2+1; i <= J2; i++){
            v[i] *= x;
        }
    }
    ll ANS = 0, s = 0;
    for(ll i = 0; i < n; i++){
        s += v[i];
        if(s < 0){
            s = 0;
        }
        ANS = max(ANS, s);
    }
    cout << ANS;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

ll v[MAXN];

ll dp[MAXN][3];

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    ll n, x; cin >> n >> x;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        dp[i][0] = max(dp[i - 1][0], 0ll) + v[i];
        ans = max(ans, dp[i][0]);
        dp[i][1] = max(max(dp[i - 1][0], dp[i - 1][1]), 0ll) + v[i] * x;
        ans = max(ans, dp[i][1]);
        dp[i][2] = max(max(dp[i - 1][2], dp[i - 1][1]), 0ll) + v[i];
        ans = max(ans, dp[i][2]);
    }
    cout << ans;
    return 0;
}