#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
const int N = five;
ll dp[N];
int main()
{
       int n,k;
       cin>>n>>k;
       ll v[n];
       arrin(v,n);
       ll c[n];
       arrin(c,n);
       set<int> ss;
       fri(i,0,n){
              ss.insert(c[i]);
       }

       while(k--)
       {
              ll a,b;
              cin>>a>>b;
              set<pll,greater<pll>> st;
              fri(i,0,n+3){dp[i] = -inf;}
              int jk = 10;
              tra(it,ss){
                     if(jk == 0){
                            break;
                     }
                     st.insert({dp[*it],*it});
                     jk--;
              }
              fri(i,0,n){
                     ll curr = dp[c[i]];
                     set<pll,greater<pll>> :: iterator it = st.begin();
                     ll gtx;
                     if(it->sc == c[i]){
                            ++it;
                            if(it == st.end()){
                                   dp[c[i]] = max({v[i]*b,curr+v[i]*a});
                                   st.clear();
                                   st.insert({dp[c[i]],c[i]});
                                   continue;
                            }
                            gtx = it->sc;
                     }
                     else{
                            gtx = it->sc;
                     }
                     dp[c[i]] = max({curr+v[i]*a,dp[gtx]+v[i]*b,v[i]*b});
                     if(st.find({curr,c[i]}) != st.end()){
                            st.erase(st.find({curr,c[i]}));
                     }
                     st.insert({dp[c[i]],c[i]});
                     if(st.size()>10){
                            it = st.end();
                            --it;
                            st.erase(it);
                     }
              }
              ll mx = 0;
              fri(i,1,n+1){
                     mx = max(mx,dp[i]);
              }
              cout<<mx<<endl;
       }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
const int N = five;
ll dp[N];
int main()
{
       int n,k;
       cin>>n>>k;
       ll v[n];
       arrin(v,n);
       ll c[n];
       arrin(c,n);
       while(k--)
       {
              ll a,b;
              cin>>a>>b;
              set<pll,greater<pll>> st;
              fri(i,0,n+3){dp[i] = -inf;}
              fri(i,1,min(n,11)){
                     st.insert({dp[i],i});
              }
              fri(i,0,n){
                     ll curr = dp[c[i]];
                     set<pll,greater<pll>> :: iterator it = st.begin();
                     ll gtx;
                     if(it->sc == c[i]){
                            ++it;
                            if(it == st.end()){
                                   dp[c[i]] = max({v[i]*b,curr+v[i]*a,0LL});
                                   st.clear();
                                   st.insert({dp[c[i]],1});
                                   continue;
                            }
                            gtx = it->sc;
                     }
                     else{
                            gtx = it->sc;
                     }
                     dp[c[i]] = max({curr+v[i]*a,dp[gtx]+v[i]*b,v[i]*b,0LL});
                     if(st.find({curr,c[i]}) != st.end()){
                            st.erase(st.find({curr,c[i]}));
                     }
                     st.insert({dp[c[i]],c[i]});
                     if(st.size()>10){
                            it = st.end();
                            --it;
                            st.erase(it);
                     }
              }
              ll mx = 0;
              fri(i,1,n+1){
                     mx = max(mx,dp[i]);
              }
              cout<<mx<<endl;
       }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e17;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = 0;
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != -1 && m[1].ss != c[i])
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] >= m[0].ff)
			{
				if(c[i] != m[0].ss)
				{
					m[1].ff = m[0].ff;
					m[1].ss = m[0].ss;
				}
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff || m[1].ss == -1)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			// if(m[0].ss == c[i])
			// 	m[0].ff = max(m[0].ff, dp[i]);
			// else if(dp[i] >= m[0].ff)
			// {
			// 	m[1].ff = m[0].ff;
			// 	m[1].ss = m[0].ss;
			// 	m[0].ff = dp[i];
			// 	m[0].ss = c[i];
			// }
			// else if(dp[i] > m[1].ff || m[1].ss == -1)
			// 	m[1].ff = dp[i], m[1].ss = c[i];
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e13;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != c[i] && m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] > m[0].ff)
			{
				m[1].ff = m[0].ff;
				m[1].ss = m[0].ss;
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e17;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = 0;
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] >= m[0].ff)
			{
				if(c[i] != m[0].ss)
				{
					m[1].ff = m[0].ff;
					m[1].ss = m[0].ss;
				}
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff || m[1].ss == -1)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			// if(m[0].ss == c[i])
			// 	m[0].ff = max(m[0].ff, dp[i]);
			// else if(dp[i] >= m[0].ff)
			// {
			// 	m[1].ff = m[0].ff;
			// 	m[1].ss = m[0].ss;
			// 	m[0].ff = dp[i];
			// 	m[0].ss = c[i];
			// }
			// else if(dp[i] > m[1].ff)
			// 	m[1].ff = dp[i], m[1].ss = c[i];
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e13;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = b * v[0];
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != c[i] && m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] > m[0].ff)
			{
				if(c[i] != m[0].ss)
				{
					m[1].ff = m[0].ff;
					m[1].ss = m[0].ss;
				}
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e13;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != c[i] && m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] > m[0].ff)
			{
				m[1].ff = m[0].ff;
				m[1].ss = m[0].ss;
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e17;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = b * v[0];
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != c[i] && m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] > m[0].ff)
			{
				if(c[i] != m[0].ss)
				{
					m[1].ff = m[0].ff;
					m[1].ss = m[0].ss;
				}
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff || m[1].ss == -1)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e17;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = 0;
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != -1 && m[1].ss != c[i])
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] >= m[0].ff)
			{
				if(c[i] != m[0].ss)
				{
					m[1].ff = m[0].ff;
					m[1].ss = m[0].ss;
				}
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if((dp[i] > m[1].ff || m[1].ss == -1) && c[i] != m[0].ss)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			// if(m[0].ss == c[i])
			// 	m[0].ff = max(m[0].ff, dp[i]);
			// else if(dp[i] >= m[0].ff)
			// {
			// 	m[1].ff = m[0].ff;
			// 	m[1].ss = m[0].ss;
			// 	m[0].ff = dp[i];
			// 	m[0].ss = c[i];
			// }
			// else if(dp[i] > m[1].ff || m[1].ss == -1)
			// 	m[1].ff = dp[i], m[1].ss = c[i];
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e17;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = 0;
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != -1 && m[1].ss != c[i])
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			// if(dp[i] >= m[0].ff)
			// {
			// 	if(c[i] != m[0].ss)
			// 	{
			// 		m[1].ff = m[0].ff;
			// 		m[1].ss = m[0].ss;
			// 	}
			// 	m[0].ff = dp[i];
			// 	m[0].ss = c[i];
			// }
			// else if(dp[i] > m[1].ff || m[1].ss == -1)
			// {
			// 	m[1].ff = dp[i];
			// 	m[1].ss = c[i];
			// }
			if(m[0].ss == c[i])
				m[0].ff = max(m[0].ff, dp[i]);
			else if(dp[i] >= m[0].ff)
			{
				m[1].ff = m[0].ff;
				m[1].ss = m[0].ss;
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff || m[1].ss == -1)
				m[1].ff = dp[i], m[1].ss = c[i];
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e15;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != c[i] && m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] > m[0].ff)
			{
				m[1].ff = m[0].ff;
				m[1].ss = m[0].ss;
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<ans<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e17;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = 0;
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != -1 && m[1].ss != c[i])
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			// if(dp[i] >= m[0].ff)
			// {
			// 	if(c[i] != m[0].ss)
			// 	{
			// 		m[1].ff = m[0].ff;
			// 		m[1].ss = m[0].ss;
			// 	}
			// 	m[0].ff = dp[i];
			// 	m[0].ss = c[i];
			// }
			// else if(dp[i] > m[1].ff || m[1].ss == -1)
			// {
			// 	m[1].ff = dp[i];
			// 	m[1].ss = c[i];
			// }
			if(m[0].ss == c[i])
				m[0].ff = max(m[0].ff, dp[i]);
			else if(dp[i] >= m[0].ff)
			{
				m[1].ff = m[0].ff;
				m[1].ss = m[0].ss;
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff)
				m[1].ff = dp[i], m[1].ss = c[i];
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e17;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = 0;
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			// if(dp[i] >= m[0].ff)
			// {
			// 	if(c[i] != m[0].ss)
			// 	{
			// 		m[1].ff = m[0].ff;
			// 		m[1].ss = m[0].ss;
			// 	}
			// 	m[0].ff = dp[i];
			// 	m[0].ss = c[i];
			// }
			// else if(dp[i] > m[1].ff || m[1].ss == -1)
			// {
			// 	m[1].ff = dp[i];
			// 	m[1].ss = c[i];
			// }
			if(m[0].ss == c[i])
				m[0].ff = max(m[0].ff, dp[i]);
			else if(dp[i] >= m[0].ff)
			{
				m[1].ff = m[0].ff;
				m[1].ss = m[0].ss;
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff)
				m[1].ff = dp[i], m[1].ss = c[i];
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e13;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = b * v[0];
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != c[i] && m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] > m[0].ff)
			{
				if(c[i] != m[0].ss)
				{
					m[1].ff = m[0].ff;
					m[1].ss = m[0].ss;
				}
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff || m[1].ss == -1)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e17;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = b * v[0];
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			if(m[1].ss != c[i] && m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] >= m[0].ff)
			{
				if(c[i] != m[0].ss)
				{
					m[1].ff = m[0].ff;
					m[1].ss = m[0].ss;
				}
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff || m[1].ss == -1)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, q, a, b;
    ll maxn = -1e13;
    vector<pair<ll, ll>> m;
    ll ans = maxn;
    m.pb(mp(maxn, -1));
    m.pb(mp(maxn, -1));
    cin>>n>>q;
    ll v[n], c[n], i, dp[n+1], ma[n+1];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    while(q--)
    {
    	ans = maxn;
    	m.clear();
    	m.pb(mp(maxn, -1));
    	m.pb(mp(maxn, -1));
    	for(i=0; i<=n; i++)
    		dp[i] = 0, ma[i] = maxn;
    	cin>>a>>b;
    	dp[0] = b * v[0];
    	m[0].ff = b * v[0];
    	m[0].ss = c[0];
    	ma[c[0]] = b * v[0];
    	ans = b * v[0];
    	for(i=1; i<n; i++)
    	{
			dp[i] = max(ma[c[i]] + a*v[i], b*v[i]);
			if(m[0].ss != c[i])
				dp[i] = max(dp[i], m[0].ff + b * v[i]);
			else if(m[1].ss != c[i] && m[1].ss != -1)
				dp[i] = max(dp[i], m[1].ff + b * v[i]);
			if(dp[i] > m[0].ff)
			{
				if(c[i] != m[0].ss)
				{
					m[1].ff = m[0].ff;
					m[1].ss = m[0].ss;
				}
				m[0].ff = dp[i];
				m[0].ss = c[i];
			}
			else if(dp[i] > m[1].ff || m[1].ss = -1)
			{
				m[1].ff = dp[i];
				m[1].ss = c[i];
			}
			ans = max(ans, dp[i]);
			ma[c[i]] = max(ma[c[i]], dp[i]);
    	}
    	cout<<max((ll) 0, ans)<<endl;
    }
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	long long n, q, i, j, k, a, b, ans, x, INF = 1LL << 61;
	cin >> n >> q;
	vector<long long> v(n), c(n);
	for (i = 0; i < n; i++) cin >> v[i];
	for (i = 0; i < n; i++) cin >> c[i];

	while (q--) {
		cin >> a >> b;
		vector<long long> dp(n + 1, -INF);
		vector<pair<long long, long long>> best(2);
		best[0] = { -INF, -1 };
		if (n == 1) best[1] = { -INF, -1 };
		else best[1] = { -INF, -2 };

		ans = 0;
		for (i = 0; i < n; i++) {
			x = v[i] * b;
			if (best[0].first != -INF) {
				if (best[0].second == c[i]) x = max(x, best[0].first + v[i] * a);
				else x = max(x, best[0].first + v[i] * b);
			}
			if (best[1].first != -INF) {
				if (best[1].second == c[i]) x = max(x, best[1].first + v[i] * a);
				else x = max(x, best[1].first + v[i] * b);
			}
			if (dp[c[i]] != -INF) x = max(x, dp[c[i]] + v[i] * a);

			if (dp[c[i]] < x) {
				dp[c[i]] = max(dp[c[i]], x);

				pair<long long, long long> bb = { dp[c[i]], c[i] };
				if (best[0] < bb) {
					if (best[0].first == c[i]) best[0] = bb;
					else {
						best[1] = best[0];
						best[0] = bb;
					}
				}
				else if (best[1] < bb) best[1] = bb;
			}

			ans = max(ans, x);
		}
		cout << ans << "\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	long long n, q, i, j, k, a, b, ans, x, INF = 1LL << 61;
	cin >> n >> q;
	vector<long long> v(n), c(n);
	for (i = 0; i < n; i++) cin >> v[i];
	for (i = 0; i < n; i++) cin >> c[i];

	while (q--) {
		cin >> a >> b;
		vector<long long> dp(n + 1, -INF);
		vector<pair<long long, long long>> best(2);
		best[0] = { -INF, -1 };
		if (n == 1) best[1] = { -INF, -1 };
		else best[1] = { -INF, -2 };

		ans = 0;
		for (i = 0; i < n; i++) {
			x = v[i] * b;
			if (best[0].first != -INF) {
				if (best[0].second == c[i]) x = max(x, best[0].first + v[i] * a);
				else x = max(x, best[0].first + v[i] * b);
			}
			if (best[1].first != -INF) {
				if (best[1].second == c[i]) x = max(x, best[1].first + v[i] * a);
				else x = max(x, best[1].first + v[i] * b);
			}
			if (dp[c[i]] != -INF) x = max(x, dp[c[i]] + v[i] * a);

			if (dp[c[i]] < x) {
				dp[c[i]] = max(dp[c[i]], x);

				pair<long long, long long> bb = { dp[c[i]], c[i] };
				if (best[0] < bb) {
					if (best[0].second == c[i]) best[0] = bb;
					else {
						best[1] = best[0];
						best[0] = bb;
					}
				}
				else if (best[1] < bb) best[1] = bb;
			}

			ans = max(ans, x);
		}
		cout << ans << "\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	long long n, q, i, j, k, a, b, ans, x, INF = 1LL << 61;
	cin >> n >> q;
	vector<long long> v(n), c(n);
	for (i = 0; i < n; i++) cin >> v[i];
	for (i = 0; i < n; i++) cin >> c[i];

	while (q--) {
		cin >> a >> b;
		vector<long long> dp(n + 1, -INF);
		vector<pair<long long, long long>> best(2);
		best[0] = { -INF, 1 };
		if (n == 1) best[1] = { -INF, 1 };
		else best[1] = { -INF, 2 };

		ans = 0;
		for (i = 0; i < n; i++) {
			x = v[i] * b;
			if (best[0].first != -INF) {
				if (best[0].second == c[i]) x = max(x, best[0].first + v[i] * a);
				else x = max(x, best[0].first + v[i] * b);
			}
			if (best[1].first != -INF) {
				if (best[1].second == c[i]) x = max(x, best[1].first + v[i] * a);
				else x = max(x, best[1].first + v[i] * b);
			}
			if (dp[c[i]] != -INF) x = max(x, dp[c[i]] + v[i] * a);

			if (dp[c[i]] < x) {
				dp[c[i]] = max(dp[c[i]], x);

				pair<long long, long long> bb = { dp[c[i]], c[i] };
				if (best[0] < bb) {
					best[1] = best[0];
					best[0] = bb;
				}
				else if (best[1] < bb) best[1] = bb;
			}

			ans = max(ans, x);
		}
		cout << ans << "\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	long long n, q, i, j, k, a, b, ans, x, INF = 1LL << 61;
	cin >> n >> q;
	vector<long long> v(n), c(n);
	for (i = 0; i < n; i++) cin >> v[i];
	for (i = 0; i < n; i++) cin >> c[i];

	while (q--) {
		cin >> a >> b;
		vector<long long> dp(n + 1, -INF);
		vector<pair<long long, long long>> best(2);
		best[0] = { -INF, -1 };
		if (n == 1) best[1] = { -INF, -1 };
		else best[1] = { -INF, -2 };

		ans = 0;
		for (i = 0; i < n; i++) {
			x = v[i] * b;
			if (best[0].first != -INF) {
				if (best[0].second == c[i]) x = max(x, best[0].first + v[i] * a);
				else x = max(x, best[0].first + v[i] * b);
			}
			if (best[1].first != -INF) {
				if (best[1].second == c[i]) x = max(x, best[1].first + v[i] * a);
				else x = max(x, best[1].first + v[i] * b);
			}
			if (dp[c[i]] != -INF) x = max(x, dp[c[i]] + v[i] * a);

			if (dp[c[i]] < x) {
				dp[c[i]] = max(dp[c[i]], x);

				pair<long long, long long> bb = { dp[c[i]], c[i] };
				if (best[0] < bb) {
					best[1] = best[0];
					best[0] = bb;
				}
				else if (best[1] < bb) best[1] = bb;
			}

			ans = max(ans, x);
		}
		cout << ans << "\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	long long n, q, i, j, k, a, b, ans, x, INF = 1LL << 61;
	cin >> n >> q;
	vector<long long> v(n), c(n);
	for (i = 0; i < n; i++) cin >> v[i];
	for (i = 0; i < n; i++) cin >> c[i];

	while (q--) {
		cin >> a >> b;
		vector<long long> dp(n + 1, -INF);
		vector<pair<long long, long long>> best(2);
		best[0] = { -INF, 1 };
		if (n == 1) best[1] = { -INF, 1 };
		else best[1] = { -INF, 2 };

		ans = 0;
		for (i = 0; i < n; i++) {
			x = v[i] * b;
			if (best[0].first != -INF) {
				if (best[0].second == c[i]) x = max(x, best[0].first + v[i] * a);
				else x = max(x, best[0].first + v[i] * b);
			}
			if (best[1].first != -INF) {
				if (best[1].second == c[i]) x = max(x, best[1].first + v[i] * a);
				else x = max(x, best[1].first + v[i] * b);
			}
			if (dp[c[i]] != -INF) x = max(x, dp[c[i]] + v[i] * a);

			dp[c[i]] = max(dp[c[i]], x);

			pair<long long, long long> bb = { dp[c[i]], c[i] };
			if (best[0] < bb) {
				best[1] = best[0];
				best[0] = bb;
			}
			else if (best[1] < bb) best[1] = bb;

			ans = max(ans, x);
		}
		cout << ans << "\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	long long n, q, i, j, k, a, b, ans, x, INF = 1LL << 62;
	cin >> n >> q;
	vector<long long> v(n), c(n);
	for (i = 0; i < n; i++) cin >> v[i];
	for (i = 0; i < n; i++) cin >> c[i];

	while (q--) {
		cin >> a >> b;
		vector<long long> dp(n + 1, -INF);
		vector<pair<long long, long long>> best(2);
		best[0] = { -INF, 1 };
		if (n == 1) best[1] = { -INF, 1 };
		else best[1] = { -INF, 2 };

		ans = 0;
		for (i = 0; i < n; i++) {
			x = v[i] * b;
			if (best[0].first != -INF) {
				if (best[0].second == c[i]) x = max(x, best[0].first + v[i] * a);
				else x = max(x, best[0].first + v[i] * b);
			}
			if (best[1].first != -INF) {
				if (best[1].second == c[i]) x = max(x, best[1].first + v[i] * a);
				else x = max(x, best[1].first + v[i] * b);
			}
			if (dp[c[i]] != -INF) x = max(x, dp[c[i]] + v[i] * a);

			dp[c[i]] = x;

			pair<long long, long long> bb = { x, c[i] };
			if (best[0] < bb) {
				best[1] = best[0];
				best[0] = bb;
			}
			else if (best[1] < bb) best[1] = bb;

			ans = max(ans, x);
		}
		cout << ans << "\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	long long n, q, i, j, k, a, b, ans, x, INF = 1LL << 60;
	cin >> n >> q;
	vector<long long> v(n), c(n);
	for (i = 0; i < n; i++) cin >> v[i];
	for (i = 0; i < n; i++) cin >> c[i];

	while (q--) {
		cin >> a >> b;
		vector<long long> dp(n + 1, -INF);
		vector<pair<long long, long long>> best(2);
		best[0] = { -INF, 1 };
		if (n == 1) best[1] = { -INF, 1 };
		else best[1] = { -INF, 2 };

		ans = 0;
		for (i = 0; i < n; i++) {
			x = v[i] * b;
			if (best[0].second == c[i]) x = max(x, best[0].first + v[i] * a);
			else x = max(x, best[0].first + v[i] * b);
			if (best[1].second == c[i]) x = max(x, best[1].first + v[i] * a);
			else x = max(x, best[1].first + v[i] * b);
			x = max(x, dp[c[i]] + v[i] * a);
			dp[c[i]] = x;

			pair<long long, long long> bb = { x, c[i] };
			if (best[0] < bb) {
				best[1] = best[0];
				best[0] = bb;
			}
			else if (best[1] < bb) best[1] = bb;

			ans = max(ans, x);
		}
		cout << ans << "\n";
	}

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n+1) dp[i]=-1e18;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = val[0] * b;
        for (int i=0; i<n; i++) {
            ll m = m1 == cor[i] ? m2 : m1;
            dp[cor[i]] = max({dp[cor[i]], dp[cor[i]] + val[i] * a, dp[m] + val[i] * b});
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (dp[m1] < dp[m2]) swap(m1, m2);
            if (m1 != cor[i] && m2 != cor[i]) {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];
bool vis[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) dp[i]=-1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = val[0] * b;
        for (int i=0; i<n; i++) {
            ll m = m1 == cor[i] ? m2 : m1;
            dp[cor[i]] = max({dp[cor[i]], dp[cor[i]] + val[i] * a, dp[m] + val[i] * b });
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) dp[i] = -1e18;
        int m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = -1e18;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];
bool vis[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) vis[i] = false, dp[i]=-1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = val[0] * b;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            if (vis[cor[i]]) dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            if (vis[m1]) dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            if (vis[m2]) dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            res = max(res, dp[cor[i]]);
            vis[cor[i]] = true;
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];
bool vis[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) vis[i] = false;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = val[0] * b;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            if (vis[cor[i]]) dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            if (vis[m1]) dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            if (vis[m2]) dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            res = max(res, dp[cor[i]]);
            vis[cor[i]] = true;
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n+1) dp[i]=-1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = val[0] * b;
        for (int i=0; i<n; i++) {
            ll m = m1 == cor[i] ? m2 : m1;
            dp[cor[i]] = max({dp[cor[i]], dp[cor[i]] + val[i] * a, dp[m] + val[i] * b});
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (dp[m1] < dp[m2]) swap(m1, m2);
            if (m1 != cor[i] && m2 != cor[i]) {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    rep(i, MAXN) dp[i] = -1e12;
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) dp[i] = -1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = -1e12;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];
bool vis[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) vis[i] = false, dp[i]=-1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = val[0] * b;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            if (vis[cor[i]]) dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            else dp[cor[i]] = val[i] * b;
            if (vis[cor[i]]) dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            if (vis[m1]) dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            if (vis[m2]) dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            res = max(res, dp[cor[i]]);
            vis[cor[i]] = true;
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) dp[i] = -1e10;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = -1-1e10;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    rep(i, MAXN) dp[i] = -1e12;
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) dp[i] = -1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = 0;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}
/*
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 200002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        for (int i=1; i<=n; i++) dp[i] = -1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = 0;
        for (int i=0; i<n; i++) {
            ll m = m1 == cor[i] ? m2 : m1;
            dp[cor[i]] = max({dp[cor[i]], dp[cor[i]] + val[i] * a, dp[m] + val[i] * b});
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (dp[m1] < dp[m2]) swap(m1, m2);
            if (m1 != cor[i] && m2 != cor[i]) {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}
*/


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];
bool vis[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) dp[i]=-1e18;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = val[0] * b;
        for (int i=0; i<n; i++) {
            ll m = m1 == cor[i] ? m2 : m1;
            dp[cor[i]] = max({dp[cor[i]], dp[cor[i]] + val[i] * a, dp[m] + val[i] * b});
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (dp[m1] < dp[m2]) swap(m1, m2);
            if (m1 != cor[i] && m2 != cor[i]) {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 200002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        for (int i=1; i<=n; i++) dp[i] = -1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = 0;
        for (int i=0; i<n; i++) {
            ll m = m1 == cor[i] ? m2 : m1;
            dp[cor[i]] = max({dp[cor[i]], dp[cor[i]] + val[i] * a, dp[m] + val[i] * b});
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (dp[m1] < dp[m2]) swap(m1, m2);
            if (m1 != cor[i] && m2 != cor[i]) {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) dp[i] = -1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = 0;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}
/*
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 200002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        for (int i=1; i<=n; i++) dp[i] = -1e12;
        ll m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        ll res = 0;
        for (int i=0; i<n; i++) {
            ll m = m1 == cor[i] ? m2 : m1;
            dp[cor[i]] = max({dp[cor[i]], dp[cor[i]] + val[i] * a, dp[m] + val[i] * b});
            res = max(res, dp[cor[i]]);
            //printf("%lld\n", cor[i]);
            if (dp[m1] < dp[m2]) swap(m1, m2);
            if (m1 != cor[i] && m2 != cor[i]) {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(res);
    }

	return 0;
}
*/


#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define prt(a) printf("%lld\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) sc(a), sc(b)
#define sc3(a, b, c) sc2(a, b), sc(c)
#define readArr(arr, n) for (int i=0; i<n; i++) sc(arr[i]);
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;

const int MAXN = 2000002;
const double EPS = 1e-9;

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

ll val[MAXN], cor[MAXN], dp[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

    ll n, q;
    sc2(n, q);
    rep(i, n) sc(val[i]);
    rep(i, n) sc(cor[i]);
    while(q--) {
        ll a, b;
        sc2(a, b);
        rep(i, n) dp[i] = -1e18;
        int m1 = MAXN-2, m2 = MAXN-1;
        ll ant, dp1, dp2;
        for (int i=0; i<n; i++) {
            ant = dp[cor[i]], dp1 = dp[m1], dp2 = dp[m2];
            dp[cor[i]] = max(dp[cor[i]], val[i] * b);
            dp[cor[i]] = max(dp[cor[i]], ant + val[i] * a);
            dp[cor[i]] = max(dp[cor[i]], dp1 + val[i] * (m1 == cor[i] ? a : b));
            dp[cor[i]] = max(dp[cor[i]], dp2 + val[i] * (m2 == cor[i] ? a : b));
            //printf("%lld\n", cor[i]);
            if (m1 == cor[i] || m2 == cor[i]) {
                if (dp[m1] < dp[m2]) swap(m1, m2);
            } else {
                if (dp[cor[i]] > dp[m1]) {
                    swap(m1, m2);
                    m1 = cor[i];
                } else {
                    if (dp[cor[i]] > dp[m2]) {
                        m2 = cor[i];
                    }
                }
            }
            //printf("%d -> %lld\n", m1, dp[m1]);
            //printf("%d -> %lld\n", m2, dp[m2]);
            //cout << "-----------------\n";
        }
        prt(dp[m1]);
    }

	return 0;
}


#include <stdio.h>
#include <iostream>
#include <set>

using namespace std;

struct MaxTracker
{
	long long val;
	std::set<int> colors;
};

const int MAX_N = 100002;
const long long MAX_S = 1000000000000000000;			//Do ket qua co the toi 10^15
long long V[MAX_N], C[MAX_N];
long long S[MAX_N];					//Ket qua tot nhat co duoc khi chon vi tri i lam duoi cua 1 mang
long long maxStoC[MAX_N];			//Ket qua tot nhat cua mang "co duoi loai i" o thoi diem dang xet
MaxTracker MT1, MT2;			//MT1. val != MT2. val && MT1.colors != MT2.colors (khac nhau tung doi mot)
int n, q, i;
long long a, b;
long long ans[501], ans_tmp;			//chua danh sach cac ket qua cua query

//Doc du lieu ban dau
void input()
{
	cin >> n >> q;
	for (i = 0; i < n; i++)
		cin >> V[i];
	for (i = 0; i < n; i++)
		cin >> C[i];
}

//Khoi tao
void init()
{
	MT1.val = -MAX_S;
	MT2.val = -MAX_S;
	MT1.colors.clear();
	MT2.colors.clear();

	/*memset(S, -MAX_S, MAX_N);
	memset(maxStoC, -MAX_S, MAX_N);*/
	for (int ii = 0; ii < n; ii++)
	{
		S[ii] = -MAX_S;
		maxStoC[ii] = -MAX_S;
	}

	ans_tmp = -MAX_S;
}

//=======XU LI========
void calculateSu(int u)
{
	S[u] = V[u] * b;			//Truong hop dau tien, chuoi chi co 1 phan tu la chinh no
	S[u] = fmax(S[u], maxStoC[C[u]] + V[u] * a);

	if (MT1.colors.size() > 1)				//neu colors co so luong > 1
	{
		S[u] = fmax(S[u], MT1.val + V[u] * b);		//chung to rang ton tai 1 mang duoi "khac loai" va co S = val, ta se noi duoi voi mang do.
	}
	else if (MT1.colors.size() == 1)
	{
		std::set<int>::iterator it = MT1.colors.find(C[u]);

		//tim ra Ci && chi co duy nhat Ci co S=val
		//=> Khong ton tai mang duoi "khac loai" nao co S = val, ta phai xet toi MT2 (vi cac colors MT2 != color MT1)
		if (it != MT1.colors.end())
			S[u] = fmax(S[u], MT2.val + V[u] * b);
		else
			S[u] = fmax(S[u], MT1.val + V[u] * b);		//neu khong tim ra Ci thi chac chan co 1 mang "khac loai" co S = val.
	}
}

//=====CAP NHAT
void update(int u)
{
	if (maxStoC[C[u]] >= S[u])
		return;
	else if (maxStoC[C[u] < S[u]])
	{
		maxStoC[C[u]] = S[u];

		//Color Ci da duoc cap nhat gia tri tong lon nhat. Vi vay phai cap nhat ca MT1, MT2
		//Luu y rang : luc nay, S[u] = maxStoC[C[u]]
		if (MT1.val < S[u])
		{
			std::set<int>::iterator it = MT1.colors.find(C[u]);

			//MT1.colors chi co 1 class duy nhat va do chinh la Ci => Chi cap nhat val, khong thay doi gi them.
			if (MT1.colors.size() == 1 && it != MT1.colors.end())
			{
				MT1.val = S[u];
			}
			else {
				MT2 = MT1;
				std::set<int>::iterator it2 = MT2.colors.find(C[u]);			//tim xem co Ci trong tap cu khong, co thi xoa di
				if (it2 != MT2.colors.end())
					MT2.colors.erase(it2);

				MT1.val = S[u];
				MT1.colors.clear();				//xoa sach danh sach cu
				MT1.colors.insert(C[u]);
			}
		}
		//Neu S = val, ta phai kiem tra xem tai MT2 co Ci khong?
		//Neu co, xoa Ci khoi MT2, roi moi them vao
		else if (MT1.val == S[u])
		{
			std::set<int>::iterator it2 = MT2.colors.find(C[u]);
			if (it2 != MT2.colors.end())
				MT2.colors.erase(it2);

			MT1.colors.insert(C[u]);		//set co kha nang tu kiem tra phan tu trung, nen minh khong can check
		}
		else if (MT2.val < S[u])
		{
			MT2.val = S[u];
			MT2.colors.clear();
			MT2.colors.insert(C[u]);
		}
		else if (MT2.val == S[u])
		{
			MT2.colors.insert(C[u]);
		}
	}
}

//Xu li
void process()
{
	for (i = 0; i < n; i++)
	{
		calculateSu(i);
		update(i);
	}

	ans_tmp = MT1.val;
	//Neu ket qua nhan duoc la am => Lay so 0
	if (ans_tmp < 0)
		ans_tmp = 0;
}

//Xuat
void output()
{
	for (i = 0; i < q; i++)
		cout << ans[i] << endl;
}

void main()
{
	input();
	for (int q0 = 0; q0 < q; q0++)
	{
		cin >> a >> b;
		init();
		process();
		ans[q0] = ans_tmp;
	}
	output();

	//system("Pause");
}

/*
10 2
-10 62 100 231 40 176 80 -10305 464 1000
1 2 1 3 6 10 2 2 3 1
150 -200
33665 28879
*/


#include <stdio.h>
#include <iostream>
#include <set>

using namespace std;

struct MaxTracker
{
	long val;
	std::set<int> colors;
};

const int MAX_N = 100002;
const long MAX_S = 10000000000000000;			//Do ket qua co the toi 10^15
long V[MAX_N], C[MAX_N];
long S[MAX_N];					//Ket qua tot nhat co duoc khi chon vi tri i lam duoi cua 1 mang
long maxStoC[MAX_N];			//Ket qua tot nhat cua mang "co duoi loai i" o thoi diem dang xet
MaxTracker MT1, MT2;			//MT1. val != MT2. val && MT1.colors != MT2.colors (khac nhau tung doi mot)
int n, q, i;
long a, b;
long ans[501], ans_tmp;			//chua danh sach cac ket qua cua query

//Doc du lieu ban dau
void input()
{
	cin >> n >> q;
	for (i = 0; i < n; i++)
		cin >> V[i];
	for (i = 0; i < n; i++)
		cin >> C[i];
}

//Khoi tao
void init()
{
	MT1.val = -MAX_S;
	MT2.val = -MAX_S;
	MT1.colors.clear();
	MT2.colors.clear();

	/*memset(S, -MAX_S, MAX_N);
	memset(maxStoC, -MAX_S, MAX_N);*/
	for (int ii = 0; ii < n; ii++)
	{
		S[ii] = -MAX_S;
		maxStoC[ii] = -MAX_S;
	}

	ans_tmp = -MAX_S;
}

//=======XU LI========
void calculateSu(int u)
{
	S[u] = V[u] * b;			//Truong hop dau tien, chuoi chi co 1 phan tu la chinh no
	S[u] = fmax(S[u], maxStoC[C[u]] + V[u] * a);

	if (MT1.colors.size() > 1)				//neu colors co so luong > 2
	{
		S[u] = fmax(S[u], MT1.val + V[u] * b);		//chung to rang ton tai 1 mang duoi "khac loai" va co S = val, ta se noi duoi voi mang do.
	}
	else if (MT1.colors.size() == 1)
	{
		std::set<int>::iterator it = MT1.colors.find(C[u]);

		//tim ra Ci && chi co duy nhat Ci co S=val
		//=> Khong ton tai mang duoi "khac loai" nao co S = val, ta phai xet toi MT2 (vi cac colors MT2 != color MT1)
		if (it != MT1.colors.end())
			S[u] = fmax(S[u], MT2.val + V[u] * b);
		else
			S[u] = fmax(S[u], MT1.val + V[u] * b);		//neu khong tim ra Ci thi chac chan co 1 mang "khac loai" co S = val.
	}
}

//=====CAP NHAT
void update(int u)
{
	maxStoC[C[u]] = fmax(maxStoC[C[u]], S[u]);
	if (MT1.val < S[u])
	{
		MT2 = MT1;
		std::set<int>::iterator it2 = MT2.colors.find(C[u]);			//tim xem co Ci trong tap cu khong, co thi xoa di
		if (it2 != MT2.colors.end())
			MT2.colors.erase(it2);

		MT1.val = S[u];
		MT1.colors.clear();				//xoa sach danh sach cu
		MT1.colors.insert(C[u]);
	}
	else if (MT1.val == S[u])
	{
		MT1.colors.insert(C[u]);		//set co kha nang tu kiem tra phan tu trung, nen minh khong can check
	}
	else if (MT2.val < S[u])
	{
		MT2.val = S[u];
		MT2.colors.clear();
		MT2.colors.insert(C[u]);
	}
	else if (MT2.val == S[u])
	{
		MT2.colors.insert(C[u]);
	}
}

//Xu li
void process()
{
	for (i = 0; i < n; i++)
	{
		calculateSu(i);
		update(i);
	}

	ans_tmp = MT1.val;
	//Neu ket qua nhan duoc la am => Lay so 0
	if (ans_tmp < 0)
		ans_tmp = 0;
}

//Xuat
void output()
{
	for (i = 0; i < q; i++)
		cout << ans[i] << endl;
}

void main()
{
	input();
	for (int q0 = 0; q0 < q; q0++)
	{
		cin >> a >> b;
		init();
		process();
		ans[q0] = ans_tmp;
	}
	output();

	system("Pause");
}


#include <stdio.h>
#include <iostream>
#include <set>

using namespace std;

struct MaxTracker
{
	long long val;
	std::set<int> colors;
};

const int MAX_N = 100003;
const long long MAX_S = 1000000000000000000;			//Do ket qua co the toi 10^15
long long V[MAX_N], C[MAX_N];
long long S[MAX_N];					//Ket qua tot nhat co duoc khi chon vi tri i lam duoi cua 1 mang
long long maxStoC[MAX_N];			//Ket qua tot nhat cua mang "co duoi loai i" o thoi diem dang xet
MaxTracker MT1, MT2;			//MT1. val != MT2. val && MT1.colors != MT2.colors (khac nhau tung doi mot)
int n, q, i;
long long a, b, val2;				//val2 la gia tri tong cao thu nhi, tuy nhien minh khong can quan tam danh sach, nen khong dung MaxTracker
long long ans[501], ans_tmp;			//chua danh sach cac ket qua cua query

//Doc du lieu ban dau
void input()
{
	cin >> n >> q;
	for (i = 0; i < n; i++)
		cin >> V[i];
	for (i = 0; i < n; i++)
		cin >> C[i];
}

//Khoi tao
void init()
{
	MT1.val = -MAX_S;
	MT2.val = -MAX_S;
	MT1.colors.clear();
	MT2.colors.clear();

	/*memset(S, -MAX_S, MAX_N);
	memset(maxStoC, -MAX_S, MAX_N);*/
	for (int ii = 0; ii <= n; ii++)			//ii = n la vi Ci co the bang n.
	{
		S[ii] = -MAX_S;
		maxStoC[ii] = -MAX_S;
	}

	ans_tmp = -MAX_S;
}

//=======XU LI========
void calculateSu(int u)
{
	S[u] = V[u] * b;			//Truong hop dau tien, chuoi chi co 1 phan tu la chinh no
	S[u] = fmax(S[u], maxStoC[C[u]] + V[u] * a);

	if (MT1.colors.size() > 1)				//neu colors co so luong > 1
	{
		S[u] = fmax(S[u], MT1.val + V[u] * b);		//chung to rang ton tai 1 mang duoi "khac loai" va co S = val, ta se noi duoi voi mang do.
	}
	else if (MT1.colors.size() == 1)
	{
		std::set<int>::iterator it = MT1.colors.find(C[u]);

		//tim ra Ci && chi co duy nhat Ci co S=val
		//=> Khong ton tai mang duoi "khac loai" nao co S = val, ta phai xet toi MT2 (vi cac colors MT2 != color MT1)
		if (it != MT1.colors.end())
			S[u] = fmax(S[u], val2 + V[u] * b);
		else
			S[u] = fmax(S[u], MT1.val + V[u] * b);		//neu khong tim ra Ci thi chac chan co 1 mang "khac loai" co S = val.
	}
}

//=====CAP NHAT
void update(int u)
{
	if (maxStoC[C[u]] >= S[u])
		return;
	else if (maxStoC[C[u]] < S[u])
	{
		maxStoC[C[u]] = S[u];

		//Color Ci da duoc cap nhat gia tri tong lon nhat. Vi vay phai cap nhat ca MT1, MT2
		//Luu y rang : luc nay, S[u] = maxStoC[C[u]]
		if (MT1.val < S[u])
		{
			std::set<int>::iterator it = MT1.colors.find(C[u]);

			//MT1.colors chi co 1 class duy nhat va do chinh la Ci => Chi cap nhat val, khong thay doi gi them.
			if (MT1.colors.size() == 1 && it != MT1.colors.end())
			{
				MT1.val = S[u];
			}
			else {
				val2 = MT1.val;

				MT1.val = S[u];
				MT1.colors.clear();				//xoa sach danh sach cu
				MT1.colors.insert(C[u]);
			}
		}
		else if (MT1.val == S[u])
		{
			MT1.colors.insert(C[u]);		//set co kha nang tu kiem tra phan tu trung, nen minh khong can check
		}
	}
}

//Xu li
void process()
{
	for (i = 0; i < n; i++)
	{
		calculateSu(i);
		update(i);
	}

	ans_tmp = MT1.val;
	//Neu ket qua nhan duoc la am => Lay so 0
	if (ans_tmp < 0)
		ans_tmp = 0;
}

//Xuat
void output()
{
	for (i = 0; i < q; i++)
		cout << ans[i] << endl;
}

void main()
{
	input();
	for (int q0 = 0; q0 < q; q0++)
	{
		cin >> a >> b;
		init();
		process();
		ans[q0] = ans_tmp;
	}
	output();

	system("Pause");
}

/*
10 3
-10 62 100 231 40 176 80 -10305 464 1000
1 2 1 3 6 10 2 2 3 1
-10000 10000
150 -200
33665 28879
*/

/*
6 1
1 -2 3 4 0 -1
1 2 1 2 1 1
1 0
*/


#include <stdio.h>
#include <iostream>
#include <set>

using namespace std;

struct MaxTracker
{
	long long val;
	std::set<int> colors;
};

const int MAX_N = 100003;
const long long MAX_S = 1000000000000000000;			//Do ket qua co the toi 10^15
long long V[MAX_N], C[MAX_N];
long long S[MAX_N];					//Ket qua tot nhat co duoc khi chon vi tri i lam duoi cua 1 mang
long long maxStoC[MAX_N];			//Ket qua tot nhat cua mang "co duoi loai i" o thoi diem dang xet
MaxTracker MT1, MT2;			//MT1. val != MT2. val && MT1.colors != MT2.colors (khac nhau tung doi mot)
int n, q, i;
long long a, b, val2;				//val2 la gia tri tong cao thu nhi, tuy nhien minh khong can quan tam danh sach, nen khong dung MaxTracker
long long ans[501], ans_tmp;			//chua danh sach cac ket qua cua query

//Doc du lieu ban dau
void input()
{
	cin >> n >> q;
	for (i = 0; i < n; i++)
		cin >> V[i];
	for (i = 0; i < n; i++)
		cin >> C[i];
}

//Khoi tao
void init()
{
	MT1.val = -MAX_S;
	MT2.val = -MAX_S;
	MT1.colors.clear();
	MT2.colors.clear();

	/*memset(S, -MAX_S, MAX_N);
	memset(maxStoC, -MAX_S, MAX_N);*/
	for (int ii = 0; ii <= n; ii++)			//ii = n la vi Ci co the bang n.
	{
		S[ii] = -MAX_S;
		maxStoC[ii] = -MAX_S;
	}

	ans_tmp = -MAX_S;
}

//=======XU LI========
void calculateSu(int u)
{
	S[u] = V[u] * b;			//Truong hop dau tien, chuoi chi co 1 phan tu la chinh no
	S[u] = fmax(S[u], maxStoC[C[u]] + V[u] * a);

	if (MT1.colors.size() > 1)				//neu colors co so luong > 1
	{
		S[u] = fmax(S[u], MT1.val + V[u] * b);		//chung to rang ton tai 1 mang duoi "khac loai" va co S = val, ta se noi duoi voi mang do.
	}
	else if (MT1.colors.size() == 1)
	{
		std::set<int>::iterator it = MT1.colors.find(C[u]);

		//tim ra Ci && chi co duy nhat Ci co S=val
		//=> Khong ton tai mang duoi "khac loai" nao co S = val, ta phai xet toi MT2 (vi cac colors MT2 != color MT1)
		if (it != MT1.colors.end())
			S[u] = fmax(S[u], val2 + V[u] * b);
		else
			S[u] = fmax(S[u], MT1.val + V[u] * b);		//neu khong tim ra Ci thi chac chan co 1 mang "khac loai" co S = val.
	}
}

//=====CAP NHAT
void update(int u)
{
	if (maxStoC[C[u]] >= S[u])
		return;
	else if (maxStoC[C[u]] < S[u])
	{
		maxStoC[C[u]] = S[u];

		//Color Ci da duoc cap nhat gia tri tong lon nhat. Vi vay phai cap nhat ca MT1, MT2
		//Luu y rang : luc nay, S[u] = maxStoC[C[u]]
		if (MT1.val < S[u])
		{
			std::set<int>::iterator it = MT1.colors.find(C[u]);

			//MT1.colors chi co 1 class duy nhat va do chinh la Ci => Chi cap nhat val, khong thay doi gi them.
			if (MT1.colors.size() == 1 && it != MT1.colors.end())
			{
				MT1.val = S[u];
			}
			else {
				val2 = MT1.val;

				MT1.val = S[u];
				MT1.colors.clear();				//xoa sach danh sach cu
				MT1.colors.insert(C[u]);
			}
		}
		else if (MT1.val == S[u])
		{
			MT1.colors.insert(C[u]);		//set co kha nang tu kiem tra phan tu trung, nen minh khong can check
		}
	}
}

//Xu li
void process()
{
	for (i = 0; i < n; i++)
	{
		calculateSu(i);
		update(i);
	}

	ans_tmp = MT1.val;
	//Neu ket qua nhan duoc la am => Lay so 0
	if (ans_tmp < 0)
		ans_tmp = 0;
}

//Xuat
void output()
{
	for (i = 0; i < q; i++)
		cout << ans[i] << endl;
}

void main()
{
	input();
	for (int q0 = 0; q0 < q; q0++)
	{
		cin >> a >> b;
		init();
		process();
		ans[q0] = ans_tmp;
	}
	output();

	//system("Pause");
}

/*
10 3
-10 62 100 231 40 176 80 -10305 464 1000
1 2 1 3 6 10 2 2 3 1
-10000 10000
150 -200
33665 28879
*/

/*
6 1
1 -2 3 4 0 -1
1 2 1 2 1 1
1 0
*/


#include <stdio.h>
#include <iostream>
#include <set>

using namespace std;

struct MaxTracker
{
	long long val;
	//std::set<int> colors;
	int color;
};

const int MAX_N = 100003;
const long long MAX_S = 1000000000000000000;			//Do ket qua co the toi 10^15
long long V[MAX_N], C[MAX_N];
long long S[MAX_N];					//Ket qua tot nhat co duoc khi chon vi tri i lam duoi cua 1 mang
long long maxStoC[MAX_N];			//Ket qua tot nhat cua mang "co duoi loai i" o thoi diem dang xet
MaxTracker MT1, MT2;			//MT1. val != MT2. val && MT1.color != MT2.color
int n, q, i;
long long a, b;
long long ans[501], ans_tmp;			//chua danh sach cac ket qua cua query

//Doc du lieu ban dau
void input()
{
	cin >> n >> q;
	for (i = 0; i < n; i++)
		cin >> V[i];
	for (i = 0; i < n; i++)
		cin >> C[i];
}

//Khoi tao
void init()
{
	MT1.val = -MAX_S;
	MT2.val = -MAX_S;

	/*memset(S, -MAX_S, MAX_N);
	memset(maxStoC, -MAX_S, MAX_N);*/
	for (int ii = 0; ii <= n; ii++)			//ii = n la vi Ci co the bang n.
	{
		//S[ii] = -MAX_S;
		maxStoC[ii] = -MAX_S;
	}

	ans_tmp = -MAX_S;
}

//=======XU LI========
void calculateSu(int u)
{
	long long tmpS = 0;
	if (MT1.color == C[u])			//cai 1 chinh la Ci, thi lay cai thu 2
		tmpS = MT2.val;
	else tmpS = MT1.val;
	//Truong hop dau tien, chuoi chi co 1 phan tu la chinh no = V[u] * b
	//S[u] = fmax(V[u] * b, fmax(maxStoC[C[u]] + V[u] * a, tmpS + V[u] * b));
	S[u] = fmax(fmax(tmpS, 0) + V[u] * b, maxStoC[C[u]] + V[u] * a);
}

//=====CAP NHAT
void update(int u)
{
	if (maxStoC[C[u]] < S[u])
	{
		maxStoC[C[u]] = S[u];

		if (MT1.val <= S[u])
		{
			if (MT1.color != C[u])			//neu la chuoi loai khac
			{
				MT2 = MT1;
				MT1.color = C[u];
			}
			MT1.val = S[u];
		}
		else if (MT2.val < S[u])
		{
			MT2.val = S[u];
			MT2.color = C[u];
		}
	}
}

//Xu li
void process()
{
	for (i = 0; i < n; i++)
	{
		calculateSu(i);
		update(i);
	}

	ans_tmp = MT1.val;
	//Neu ket qua nhan duoc la am => Lay so 0
	if (ans_tmp < 0)
		ans_tmp = 0;
}

//Xuat
void output()
{
	for (i = 0; i < q; i++)
		cout << ans[i] << endl;
}

void main()
{
	input();
	for (int q0 = 0; q0 < q; q0++)
	{
		cin >> a >> b;
		init();
		process();
		cout << ans_tmp;
	}
	//output();

	//system("Pause");
}


#include <stdio.h>
#include <iostream>
#include <set>

using namespace std;

struct MaxTracker
{
	long long val;
	//std::set<int> colors;
	int color;
};

const int MAX_N = 100003;
const long long MAX_S = 1000000000000000000;			//Do ket qua co the toi 10^15
long long V[MAX_N], C[MAX_N];
long long S[MAX_N];					//Ket qua tot nhat co duoc khi chon vi tri i lam duoi cua 1 mang
long long maxStoC[MAX_N];			//Ket qua tot nhat cua mang "co duoi loai i" o thoi diem dang xet
MaxTracker MT1, MT2;			//MT1. val != MT2. val && MT1.color != MT2.color
int n, q, i;
long long a, b;
long long ans[501], ans_tmp;			//chua danh sach cac ket qua cua query

//Doc du lieu ban dau
void input()
{
	cin >> n >> q;
	for (i = 0; i < n; i++)
		cin >> V[i];
	for (i = 0; i < n; i++)
		cin >> C[i];
}

//Khoi tao
void init()
{
	MT1.val = -MAX_S;
	MT2.val = -MAX_S;

	/*memset(S, -MAX_S, MAX_N);
	memset(maxStoC, -MAX_S, MAX_N);*/
	for (int ii = 0; ii <= n; ii++)			//ii = n la vi Ci co the bang n.
	{
		S[ii] = -MAX_S;
		maxStoC[ii] = -MAX_S;
	}

	ans_tmp = -MAX_S;
}

//=======XU LI========
void calculateSu(int u)
{
	//if (MT1.colors.size() > 1)				//neu colors co so luong > 1
	//{
	//	S[u] = fmax(S[u], MT1.val + V[u] * b);		//chung to rang ton tai 1 mang duoi "khac loai" va co S = val, ta se noi duoi voi mang do.
	//}
	//else if (MT1.colors.size() == 1)
	//{
	//	std::set<int>::iterator it = MT1.colors.find(C[u]);
	//	//tim ra Ci && chi co duy nhat Ci co S=val
	//	//=> Khong ton tai mang duoi "khac loai" nao co S = val, ta phai xet toi MT2 (vi cac colors MT2 != color MT1)
	//	if (it != MT1.colors.end())
	//		S[u] = fmax(S[u], val2 + V[u] * b);
	//	else
	//		S[u] = fmax(S[u], MT1.val + V[u] * b);		//neu khong tim ra Ci thi chac chan co 1 mang "khac loai" co S = val.
	//}

	long long tmpS = 0;
	if (MT1.color == C[i])			//cai 1 chinh la Ci, thi lay cai thu 2
		tmpS = MT2.val;
	else tmpS = MT1.val;
	//Truong hop dau tien, chuoi chi co 1 phan tu la chinh no = V[u] * b
	S[u] = fmax(V[u] * b, fmax(maxStoC[C[u]] + V[u] * a, tmpS + V[u] * b));
}

//=====CAP NHAT
void update(int u)
{
	//if (maxStoC[C[u]] >= S[u])
	//	return;
	//else if (maxStoC[C[u]] < S[u])
	//{
	//	maxStoC[C[u]] = S[u];
	//	//Color Ci da duoc cap nhat gia tri tong lon nhat. Vi vay phai cap nhat ca MT1, MT2
	//	//Luu y rang : luc nay, S[u] = maxStoC[C[u]]
	//	if (MT1.val < S[u])
	//	{
	//		std::set<int>::iterator it = MT1.colors.find(C[u]);
	//		//MT1.colors chi co 1 class duy nhat va do chinh la Ci => Chi cap nhat val, khong thay doi gi them.
	//		if (MT1.colors.size() == 1 && it != MT1.colors.end())
	//		{
	//			MT1.val = S[u];
	//		}
	//		else {
	//			val2 = MT1.val;
	//			MT1.val = S[u];
	//			MT1.colors.clear();				//xoa sach danh sach cu
	//			MT1.colors.insert(C[u]);
	//		}
	//	}
	//	else if (MT1.val == S[u])
	//	{
	//		MT1.colors.insert(C[u]);		//set co kha nang tu kiem tra phan tu trung, nen minh khong can check
	//	}
	//}
	if (maxStoC[C[u]] < S[u])
	{
		maxStoC[C[u]] = S[u];

		if (MT1.val <= S[u])
		{
			if (MT1.color != C[u])			//neu la chuoi loai khac
			{
				MT2 = MT1;
				MT1.color = C[u];
			}
			MT1.val = S[u];
		}
		else if (MT2.val < S[u])
		{
			MT2.val = S[u];
			MT2.color = C[u];
		}
	}
}

//Xu li
void process()
{
	for (i = 0; i < n; i++)
	{
		calculateSu(i);
		update(i);
	}

	ans_tmp = MT1.val;
	//Neu ket qua nhan duoc la am => Lay so 0
	if (ans_tmp < 0)
		ans_tmp = 0;
}

//Xuat
void output()
{
	for (i = 0; i < q; i++)
		cout << ans[i] << endl;
}

void main()
{
	input();
	for (int q0 = 0; q0 < q; q0++)
	{
		cin >> a >> b;
		init();
		process();
		ans[q0] = ans_tmp;
	}
	output();

	//system("Pause");
}

/*
10 3
-10 62 100 231 40 176 80 -10305 464 1000
1 2 1 3 6 10 2 2 3 1
-10000 10000
150 -200
33665 28879
*/

/*
6 3
1 -2 3 4 0 -1
1 2 1 2 1 1
5 1
-2 1
1 0
*/

/*
4 1
-3 6 -1 2
1 2 3 1
1 -1
*/


#include <stdio.h>
#include <iostream>
#include <set>

using namespace std;

struct MaxTracker
{
	long long val;
	std::set<int> colors;
};

const int MAX_N = 100002;
const long long MAX_S = 1000000000000000000;			//Do ket qua co the toi 10^15
long long V[MAX_N], C[MAX_N];
long long S[MAX_N];					//Ket qua tot nhat co duoc khi chon vi tri i lam duoi cua 1 mang
long long maxStoC[MAX_N];			//Ket qua tot nhat cua mang "co duoi loai i" o thoi diem dang xet
MaxTracker MT1, MT2;			//MT1. val != MT2. val && MT1.colors != MT2.colors (khac nhau tung doi mot)
int n, q, i;
long long a, b;
long long ans[501], ans_tmp;			//chua danh sach cac ket qua cua query

//Doc du lieu ban dau
void input()
{
	cin >> n >> q;
	for (i = 0; i < n; i++)
		cin >> V[i];
	for (i = 0; i < n; i++)
		cin >> C[i];
}

//Khoi tao
void init()
{
	MT1.val = -MAX_S;
	MT2.val = -MAX_S;
	MT1.colors.clear();
	MT2.colors.clear();

	/*memset(S, -MAX_S, MAX_N);
	memset(maxStoC, -MAX_S, MAX_N);*/
	for (int ii = 0; ii < n; ii++)
	{
		S[ii] = -MAX_S;
		maxStoC[ii] = -MAX_S;
	}

	ans_tmp = -MAX_S;
}

//=======XU LI========
void calculateSu(int u)
{
	S[u] = V[u] * b;			//Truong hop dau tien, chuoi chi co 1 phan tu la chinh no
	S[u] = fmax(S[u], maxStoC[C[u]] + V[u] * a);

	if (MT1.colors.size() > 1)				//neu colors co so luong > 1
	{
		S[u] = fmax(S[u], MT1.val + V[u] * b);		//chung to rang ton tai 1 mang duoi "khac loai" va co S = val, ta se noi duoi voi mang do.
	}
	else if (MT1.colors.size() == 1)
	{
		std::set<int>::iterator it = MT1.colors.find(C[u]);

		//tim ra Ci && chi co duy nhat Ci co S=val
		//=> Khong ton tai mang duoi "khac loai" nao co S = val, ta phai xet toi MT2 (vi cac colors MT2 != color MT1)
		if (it != MT1.colors.end())
			S[u] = fmax(S[u], MT2.val + V[u] * b);
		else
			S[u] = fmax(S[u], MT1.val + V[u] * b);		//neu khong tim ra Ci thi chac chan co 1 mang "khac loai" co S = val.
	}
}

//=====CAP NHAT
void update(int u)
{
	maxStoC[C[u]] = fmax(maxStoC[C[u]], S[u]);
	if (MT1.val < S[u])
	{
		std::set<int>::iterator it = MT1.colors.find(C[u]);

		//MT1.colors chi co 1 class duy nhat va do chinh la Ci => Chi cap nhat val, khong thay doi gi them.
		if (MT1.colors.size() == 1 && it != MT1.colors.end())
		{
			MT1.val = S[u];
		}
		else {
			MT2 = MT1;
			std::set<int>::iterator it2 = MT2.colors.find(C[u]);			//tim xem co Ci trong tap cu khong, co thi xoa di
			if (it2 != MT2.colors.end())
				MT2.colors.erase(it2);

			MT1.val = S[u];
			MT1.colors.clear();				//xoa sach danh sach cu
			MT1.colors.insert(C[u]);
		}
	}
	else if (MT1.val == S[u])
	{
		MT1.colors.insert(C[u]);		//set co kha nang tu kiem tra phan tu trung, nen minh khong can check
	}
	else if (MT2.val < S[u])
	{
		MT2.val = S[u];
		MT2.colors.clear();
		MT2.colors.insert(C[u]);
	}
	else if (MT2.val == S[u])
	{
		MT2.colors.insert(C[u]);
	}
}

//Xu li
void process()
{
	for (i = 0; i < n; i++)
	{
		calculateSu(i);
		update(i);
	}

	ans_tmp = MT1.val;
	//Neu ket qua nhan duoc la am => Lay so 0
	if (ans_tmp < 0)
		ans_tmp = 0;
}

//Xuat
void output()
{
	for (i = 0; i < q; i++)
		cout << ans[i] << endl;
}

void main()
{
	input();
	for (int q0 = 0; q0 < q; q0++)
	{
		cin >> a >> b;
		init();
		process();
		ans[q0] = ans_tmp;
	}
	output();
}

/*
10 2
-10 62 100 231 40 176 80 -10305 464 1000
1 2 1 3 6 10 2 2 3 1
150 -200
33665 28879
*/


#include <stdio.h>
#include <iostream>
#include <set>

using namespace std;

struct MaxTracker
{
	long long val;
	//std::set<int> colors;
	int color;
};

const int MAX_N = 100003;
const long long MAX_S = 1000000000000000000;			//Do ket qua co the toi 10^15
long long V[MAX_N], C[MAX_N];
long long S[MAX_N];					//Ket qua tot nhat co duoc khi chon vi tri i lam duoi cua 1 mang
long long maxStoC[MAX_N];			//Ket qua tot nhat cua mang "co duoi loai i" o thoi diem dang xet
MaxTracker MT1, MT2;			//MT1. val != MT2. val && MT1.color != MT2.color
int n, q, i;
long long a, b;
long long ans[501], ans_tmp;			//chua danh sach cac ket qua cua query

//Doc du lieu ban dau
void input()
{
	cin >> n >> q;
	for (i = 0; i < n; i++)
		cin >> V[i];
	for (i = 0; i < n; i++)
		cin >> C[i];
}

//Khoi tao
void init()
{
	MT1.val = -MAX_S;
	MT2.val = -MAX_S;

	/*memset(S, -MAX_S, MAX_N);
	memset(maxStoC, -MAX_S, MAX_N);*/
	for (int ii = 0; ii <= n; ii++)			//ii = n la vi Ci co the bang n.
	{
		S[ii] = -MAX_S;
		maxStoC[ii] = -MAX_S;
	}

	ans_tmp = -MAX_S;
}

//=======XU LI========
void calculateSu(int u)
{
	//if (MT1.colors.size() > 1)				//neu colors co so luong > 1
	//{
	//	S[u] = fmax(S[u], MT1.val + V[u] * b);		//chung to rang ton tai 1 mang duoi "khac loai" va co S = val, ta se noi duoi voi mang do.
	//}
	//else if (MT1.colors.size() == 1)
	//{
	//	std::set<int>::iterator it = MT1.colors.find(C[u]);
	//	//tim ra Ci && chi co duy nhat Ci co S=val
	//	//=> Khong ton tai mang duoi "khac loai" nao co S = val, ta phai xet toi MT2 (vi cac colors MT2 != color MT1)
	//	if (it != MT1.colors.end())
	//		S[u] = fmax(S[u], val2 + V[u] * b);
	//	else
	//		S[u] = fmax(S[u], MT1.val + V[u] * b);		//neu khong tim ra Ci thi chac chan co 1 mang "khac loai" co S = val.
	//}

	long long tmpS = 0;
	if (MT1.color == C[i])			//cai 1 chinh la Ci, thi lay cai thu 2
		tmpS = MT2.val;
	else tmpS = MT1.val;
	//Truong hop dau tien, chuoi chi co 1 phan tu la chinh no = V[u] * b
	S[u] = fmax(V[u] * b, fmax(maxStoC[C[u]] + V[u] * a, tmpS + V[u] * b));
}

//=====CAP NHAT
void update(int u)
{
	//if (maxStoC[C[u]] >= S[u])
	//	return;
	//else if (maxStoC[C[u]] < S[u])
	//{
	//	maxStoC[C[u]] = S[u];
	//	//Color Ci da duoc cap nhat gia tri tong lon nhat. Vi vay phai cap nhat ca MT1, MT2
	//	//Luu y rang : luc nay, S[u] = maxStoC[C[u]]
	//	if (MT1.val < S[u])
	//	{
	//		std::set<int>::iterator it = MT1.colors.find(C[u]);
	//		//MT1.colors chi co 1 class duy nhat va do chinh la Ci => Chi cap nhat val, khong thay doi gi them.
	//		if (MT1.colors.size() == 1 && it != MT1.colors.end())
	//		{
	//			MT1.val = S[u];
	//		}
	//		else {
	//			val2 = MT1.val;
	//			MT1.val = S[u];
	//			MT1.colors.clear();				//xoa sach danh sach cu
	//			MT1.colors.insert(C[u]);
	//		}
	//	}
	//	else if (MT1.val == S[u])
	//	{
	//		MT1.colors.insert(C[u]);		//set co kha nang tu kiem tra phan tu trung, nen minh khong can check
	//	}
	//}
	if (maxStoC[C[u]] < S[u])
		maxStoC[C[u]] = S[u];

	if (MT1.val < S[u])
	{
		MT2 = MT1;
		MT1.val = S[u];
		MT1.color = C[u];
	}
	else if (MT2.val < S[u])
	{
		MT2.val = S[u];
		MT2.color = C[u];
	}
}

//Xu li
void process()
{
	for (i = 0; i < n; i++)
	{
		calculateSu(i);
		update(i);
	}

	ans_tmp = MT1.val;
	//Neu ket qua nhan duoc la am => Lay so 0
	if (ans_tmp < 0)
		ans_tmp = 0;
}

//Xuat
void output()
{
	for (i = 0; i < q; i++)
		cout << ans[i] << endl;
}

void main()
{
	input();
	for (int q0 = 0; q0 < q; q0++)
	{
		cin >> a >> b;
		init();
		process();
		ans[q0] = ans_tmp;
	}
	output();

	//system("Pause");
}

/*
10 3
-10 62 100 231 40 176 80 -10305 464 1000
1 2 1 3 6 10 2 2 3 1
-10000 10000
150 -200
33665 28879
*/

/*
6 3
1 -2 3 4 0 -1
1 2 1 2 1 1
5 1
-2 1
1 0
*/

/*
4 1
-3 6 -1 2
1 2 3 1
1 -1
*/