#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <map>
using namespace std;

const int H=(1<<17);
const int N=100000+10;
int n,q,i,c[N],same[N],diff[N],last[N],thelast;
long long v[N],answer,ans[N],a,b,tmpa,tmpb,_this,_that;
long long T[2*H],ret;
long long maxmaxmax=-1000000000000000000LL;

void _upd(int i,long long &val)
{
 i+=H-1;
 T[i]=max(T[i],val);
 while ( i>1 )
  {
   i/=2;
   T[i]=max(T[i*2],T[i*2+1]);
  }
}

long long _ans(int l,int r)
{
 ret=-1000000000000000000LL;
 l+=H-1;
 r+=H-1;

 while ( l<r )
  {
   ret=max(ret,max(T[l],T[r]));
   if ( l%2==1 ) l++;
   if ( r%2==0 ) r--;
   l/=2;
   r/=2;
  }
 if ( l==r ) ret=max(ret,T[l]);

 return ret;
}

main()
{
 scanf("%d%d",&n,&q);
 for ( i=1;i<=n;i++ )
  scanf("%I64d",&v[i]);
 for ( i=1;i<=n;i++ )
  scanf("%d",&c[i]);

 while ( q-- )
  {
   scanf("%I64d%I64d",&a,&b);
   answer=0;
   fill(T,T+2*H+1,0);
   for ( i=1;i<=n;i++ )
    T[H-1+i]=maxmaxmax;

   for ( i=1;i<=n;i++ )
    {
     _this=T[H-1+c[i]];
     _that=max(_ans(1,c[i]-1),_ans(c[i]+1,100000));

     ans[i]=max(b*v[i],b*v[i]+_that);
     if ( last[c[i]] )
       ans[i]=max(ans[i],a*v[i]+_this);

     last[c[i]]=1;
     answer=max(answer,ans[i]);

     _upd(c[i],ans[i]);
    }
   printf("%I64d\n",answer);
  }
}


#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <map>
using namespace std;

const int N=100000+10;
int n,q,i,c[N],last[N],jj1,jj2;
long long v[N],answer,ans[N],a,b,_this,_that,best[N],max1,max2;
long long maxmaxmax=-1000000000000000000LL;

main()
{
 scanf("%d%d",&n,&q);
 for ( i=1;i<=n;i++ )
  scanf("%I64d",&v[i]);
 for ( i=1;i<=n;i++ )
  scanf("%d",&c[i]);

 while ( q-- )
  {
   scanf("%I64d%I64d",&a,&b);

   answer=0;
   for ( i=1;i<=n;i++ )
    {
     best[i]=maxmaxmax;
     last[1]=0;
    }
   max1=max2=maxmaxmax;

   for ( i=1;i<=n;i++ )
    {
     _this=best[c[i]];

     if ( jj1!=c[i] ) _that=max1;
                else _that=max2;

     ans[i]=max(b*v[i],b*v[i]+_that);
     if ( last[c[i]] )
       ans[i]=max(ans[i],a*v[i]+_this);

     last[c[i]]=1;
     answer=max(answer,ans[i]);

     if ( ans[i]>max1 )
      {
       jj2=jj1;
       max2=max1;
       jj1=c[i];
       max1=ans[i];
      }
     else if ( ans[i]>max2 )
      {
       jj2=c[i];
       max2=ans[i];
      }

     if ( ans[i]>best[c[i]] )
      best[c[i]]=ans[i];
    }
   printf("%I64d\n",answer);
  }
}


#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <map>
using namespace std;

const int N=100000+10;
int n,q,i,c[N],jj1,jj2;
long long v[N],answer,ans[N],a,b,_this,_that,best[N],max1,max2;
long long maxmaxmax=-1000000000000000000LL;

main()
{
 scanf("%d%d",&n,&q);
 for ( i=1;i<=n;i++ )
  scanf("%I64d",&v[i]);
 for ( i=1;i<=n;i++ )
  scanf("%d",&c[i]);

 while ( q-- )
  {
   scanf("%I64d%I64d",&a,&b);

   answer=0;
   for ( i=1;i<=n;i++ )
    best[i]=maxmaxmax;
   max1=max2=maxmaxmax;
   jj1=jj2=-1;

   for ( i=1;i<=n;i++ )
    {
     _this=best[c[i]];

     if ( jj1!=c[i] ) _that=max1;
                else _that=max2;

     ans[i]=max(b*v[i],b*v[i]+_that);
     ans[i]=max(ans[i],a*v[i]+_this);

     answer=max(answer,ans[i]);

     if ( jj1==c[i] ) max1=max(max1,ans[i]);
     if ( jj2==c[i] ) max2=max(max2,ans[i]);

     if ( max2>max1 )
      {
       swap(max2,max1);
       swap(jj1,jj2);
      }

     if ( ans[i]>max1 )
      {
       jj2=jj1;
       max2=max1;
       jj1=c[i];
       max1=ans[i];
      }
     else if ( ans[i]>max2 )
      {
       jj2=c[i];
       max2=ans[i];
      }

     if ( ans[i]>best[c[i]] )
      best[c[i]]=ans[i];

    }
   printf("%I64d\n",answer);
  }
}


#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <map>
using namespace std;

const int H=(1<<20);
const int N=100000+10;
int n,q,i,c[N],same[N],diff[N],last[N],thelast;
long long v[N],answer,ans[N],a,b,tmpa,tmpb,_this,_that;
long long T[2*H],ret;
long long maxmaxmax=-1000000000000000000LL;

void _upd(int i,long long &val)
{
 i+=H-1;
 T[i]=max(T[i],val);
 while ( i>1 )
  {
   i/=2;
   T[i]=max(T[i*2],T[i*2+1]);
  }
}

long long _ans(int l,int r)
{
 ret=-1000000000000000000LL;
 l+=H-1;
 r+=H-1;

 while ( l<r )
  {
   ret=max(ret,max(T[l],T[r]));
   if ( l%2==1 ) l++;
   if ( r%2==0 ) r--;
   l/=2;
   r/=2;
  }
 if ( l==r ) ret=max(ret,T[l]);

 return ret;
}

main()
{
 scanf("%I64d%I64d",&n,&q);
 for ( i=1;i<=n;i++ )
  scanf("%I64d",&v[i]);
 for ( i=1;i<=n;i++ )
  scanf("%I64d",&c[i]);

 while ( q-- )
  {
   scanf("%I64d%I64d",&a,&b);
   answer=0;
   fill(T,T+2*H+1,0);
   for ( i=1;i<=n;i++ )
    T[H-1+i]=maxmaxmax;

   for ( i=1;i<=n;i++ )
    {
     _this=T[H-1+c[i]];
     _that=max(_ans(1,c[i]-1),_ans(c[i]+1,100000));

     ans[i]=max(b*v[i],b*v[i]+_that);
     if ( last[c[i]] )
       ans[i]=max(ans[i],a*v[i]+_this);

     last[c[i]]=1;
     answer=max(answer,ans[i]);

     _upd(c[i],ans[i]);
    }
   printf("%I64d\n",answer);
  }
}


#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <map>
using namespace std;

const int H=(1<<16);
const int N=100000+10;
int n,q,i,c[N],same[N],diff[N],last[N],thelast;
long long v[N],answer,ans[N],a,b,tmpa,tmpb,_this,_that;
long long T[2*H],ret;
long long maxmaxmax=-1000000000000000000LL;

void _upd(int i,long long &val)
{
 i+=H-1;
 T[i]=max(T[i],val);
 while ( i>1 )
  {
   i/=2;
   T[i]=max(T[i*2],T[i*2+1]);
  }
}

long long _ans(int l,int r)
{
 ret=-1000000000000000000LL;
 l+=H-1;
 r+=H-1;

 while ( l<r )
  {
   ret=max(ret,max(T[l],T[r]));
   if ( l%2==1 ) l++;
   if ( r%2==0 ) r--;
   l/=2;
   r/=2;
  }
 if ( l==r ) ret=max(ret,T[l]);

 return ret;
}

main()
{
 scanf("%d%d",&n,&q);
 for ( i=1;i<=n;i++ )
  scanf("%I64d",&v[i]);
 for ( i=1;i<=n;i++ )
  scanf("%d",&c[i]);

 while ( q-- )
  {
   scanf("%I64d%I64d",&a,&b);
   answer=0;
   fill(T,T+2*H+1,0);
   for ( i=1;i<=n;i++ )
    T[H-1+i]=maxmaxmax;

   for ( i=1;i<=n;i++ )
    {
     _this=T[H-1+c[i]];
     _that=max(_ans(1,c[i]-1),_ans(c[i]+1,100000));

     ans[i]=max(b*v[i],b*v[i]+_that);
     if ( last[c[i]] )
       ans[i]=max(ans[i],a*v[i]+_this);

     last[c[i]]=1;
     answer=max(answer,ans[i]);

     _upd(c[i],ans[i]);
    }
   printf("%I64d\n",answer);
  }
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

long long maxx,maxx1;
long long ind,ind1;

struct bet
{
	long long a,b,c;
};
bet dp[100050],heap[100050];

struct bet1
{
	int a,b,c;
};
bet1 f[100050];

int main()
{
	scanf("%d %d",&n,&m);

	for (int i=0;i<n;i++) scanf("%d",&f[i].a);
	for (int i=0;i<n;i++) scanf("%d",&f[i].b);

	for (int i=0;i<m;i++)
	{long long k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		maxx=dp[f[0].b].a;ind=f[0].b;
		maxx1=-LLONG_MAX;

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(ind == f[j].b) l1=maxx1; else l1=maxx;

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

/*			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<" "<<l1<<" "<<k<<" "<<l<<endl;
*/
			k1=max1(k1,l1);

			if(k1 > dp[f[j].b].a)
			{
				dp[f[j].b].a=k1;

				if(maxx <= k1)
				{
					if(ind == f[j].b) maxx=k1;
					else {maxx1=maxx;ind1=ind;maxx=k1;ind=f[j].b;}
				}
				else if(k1 > maxx1) {maxx1=k1;ind1=f[j].b;}
			}
		}

		heap_len=0;

		long long pr=maxx;

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

struct bet
{
	long long a,b,c;
};
bet f[100050],dp[100050],heap[100050];

void swap(int x, int y)
{
	bet t=heap[x];heap[x]=heap[y];heap[y]=t;

	int t1=dp[heap[x].b].b;dp[heap[x].b].b=dp[heap[y].b].b;dp[heap[y].b].b=t1;
}

	void push(int x, int y)
	{
		heap[heap_len].a=x;heap[heap_len].b=y;

		int s=heap_len;heap_len++;

		while(s>0)
		{
			if(heap[(s-1)/2].a < heap[s].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

	void rep(int x, int y)
	{
		heap[x].a=y;

		int s=x;

		while(s*2+1 < heap_len)
		{
			int k=s*2+1,l=s*2+2;

			if(heap[k].a<heap[l].a && l<heap_len) k=l;

			if(heap[k].a>heap[s].a) swap(s,k),s=k;
			else break;
		}
	}

int main()
{
	cin>>n>>m;

	for (int i=0;i<n;i++) cin>>f[i].a;
	for (int i=0;i<n;i++) cin>>f[i].b;

	for (int i=0;i<m;i++)
	{int k,l;
		cin>>k>>l;

		if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		dp[f[0].b].b=heap_len;

		push(dp[f[0].b].a,f[0].b);

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(heap[0].b != f[j].b && heap_len != 0) l1=heap[0].a;
			else
			{
				if(heap_len == 2) l1=heap[1].a;
				if(heap_len > 2) l1=max1(heap[1].a,heap[2].a);
			}

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

			//cout<<"--->"<<k1<<" "<<l1<<endl;

			k1=max1(k1,l1);

			if(dp[f[j].b].a == -LLONG_MAX) dp[f[j].b].a=k1,dp[f[j].b].b=heap_len,push(k1,f[j].b);
			else if(k1 > dp[f[j].b].a) dp[f[j].b].a=k1,rep(dp[f[j].b].b,k1);
		}

		heap_len=0;

		long long pr=-LLONG_MAX;

		for (int j=1;j<=n;j++) pr=max1(pr,dp[j].a);

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

struct bet
{
	long long a,b,c;
};
bet f[100050],dp[100050],heap[100050];

void swap(int x, int y)
{
	bet t=heap[x];heap[x]=heap[y];heap[y]=t;

	int t1=dp[heap[x].b].b;dp[heap[x].b].b=dp[heap[y].b].b;dp[heap[y].b].b=t1;
}

	void push(int x, int y)
	{
		heap[heap_len].a=x;heap[heap_len].b=y;

		int s=heap_len;heap_len++;

		while(s>0)
		{
			if(heap[(s-1)/2].a < heap[s].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

	void rep(int x, int y)
	{
		heap[x].a=y;

		int s=x;

		while(s>0)
		{
			if(heap[s].a>heap[(s-1)/2].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

int main()
{
	cin>>n>>m;

	for (int i=0;i<n;i++) cin>>f[i].a;
	for (int i=0;i<n;i++) cin>>f[i].b;

	for (int i=0;i<m;i++)
	{int k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		dp[f[0].b].b=heap_len;

		push(dp[f[0].b].a,f[0].b);

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(heap[0].b != f[j].b && heap_len != 0) l1=heap[0].a;
			else
			{
				if(heap_len == 2) l1=heap[1].a;
				if(heap_len > 2) l1=max1(heap[1].a,heap[2].a);
			}

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

			//cout<<"--->"<<k1<<" "<<l1<<endl;

			k1=max1(k1,l1);

			if(dp[f[j].b].a == -LLONG_MAX) dp[f[j].b].a=k1,dp[f[j].b].b=heap_len,push(k1,f[j].b);
			else if(k1 > dp[f[j].b].a) dp[f[j].b].a=k1,rep(dp[f[j].b].b,k1);
		}

		heap_len=0;

		long long pr=-LLONG_MAX;

		for (int j=1;j<=n;j++) pr=max1(pr,dp[j].a);

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

struct bet
{
	long long a,b,c;
};
bet f[100050],dp[100050],heap[100050];

void swap(int x, int y)
{
	bet t=heap[x];heap[x]=heap[y];heap[y]=t;

	int t1=dp[heap[x].b].b;dp[heap[x].b].b=dp[heap[y].b].b;dp[heap[y].b].b=t1;
}

	void push(int x, int y)
	{
		heap[heap_len].a=x;heap[heap_len].b=y;

		int s=heap_len;heap_len++;

		while(s>0)
		{
			if(heap[(s-1)/2].a < heap[s].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

	void rep(int x, int y)
	{
		heap[x].a=y;

		int s=x;

		while(s>0)
		{
			if(heap[s].a>heap[(s-1)/2].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

int main()
{
	cin>>n>>m;

	for (int i=0;i<n;i++) cin>>f[i].a;
	for (int i=0;i<n;i++) cin>>f[i].b;

	for (int i=0;i<m;i++)
	{int k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		dp[f[0].b].b=heap_len;

		push(dp[f[0].b].a,f[0].b);

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(heap[0].b != f[j].b && heap_len != 0) l1=heap[0].a;
			else
			{
				if(heap_len == 2) l1=heap[1].a;
				if(heap_len > 2) l1=max1(heap[1].a,heap[2].a);
			}

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

			k1=max1(k1,l1);

			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<" "<<k<<" "<<l<<endl;

			if(dp[f[j].b].a == -LLONG_MAX) dp[f[j].b].a=k1,dp[f[j].b].b=heap_len,push(k1,f[j].b);
			else if(k1 > dp[f[j].b].a) dp[f[j].b].a=k1,rep(dp[f[j].b].b,k1);
		}

		heap_len=0;

		long long pr=-LLONG_MAX;

		for (int j=1;j<=n;j++) pr=max1(pr,dp[j].a);

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

long long maxx,maxx1;
long long ind,ind1;

struct bet
{
	long long a,b,c;
};
bet dp[100050],heap[100050];

struct bet1
{
	int a,b,c;
};
bet1 f[100050];

int main()
{
	scanf("%d %d",&n,&m);

	for (int i=0;i<n;i++) scanf("%d",&f[i].a);
	for (int i=0;i<n;i++) scanf("%d",&f[i].b);

	for (int i=0;i<m;i++)
	{long long k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		maxx=dp[f[0].b].a;ind=f[0].b;
		maxx1=-LLONG_MAX;

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(ind == f[j].b) l1=maxx1; else l1=maxx;

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

/*			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<" "<<l1<<" "<<k<<" "<<l<<endl;
*/
			k1=max1(k1,l1);

			if(maxx <= k1)
			{
				if(ind == f[j].b) maxx=k1;
				else maxx1=maxx;ind1=ind;maxx=k1;ind=f[j].b;
			}
			else if(k1 > maxx1) {maxx1=k1;ind1=f[j].b;}

			dp[f[j].b].a=max1(dp[f[j].b].a,k1);
		}

		heap_len=0;

		long long pr=maxx;

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

struct bet
{
	long long a,b,c;
};
bet f[100050],dp[100050],heap[100050];

void swap(int x, int y)
{
	bet t=heap[x];heap[x]=heap[y];heap[y]=t;

	long long t1=dp[heap[x].b].b;dp[heap[x].b].b=dp[heap[y].b].b;dp[heap[y].b].b=t1;
}

	void push(long long x, long long y)
	{
		heap[heap_len].a=x;heap[heap_len].b=y;

		long long s=heap_len;heap_len++;

		while(s>0)
		{
			if(heap[(s-1)/2].a < heap[s].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

	void rep(long long x, long long y)
	{
		heap[x].a=y;

		long long s=x;

		while(s>0)
		{
			if(heap[s].a>heap[(s-1)/2].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

int main()
{
	cin>>n>>m;

	for (int i=0;i<n;i++) cin>>f[i].a;
	for (int i=0;i<n;i++) cin>>f[i].b;

	for (int i=0;i<m;i++)
	{long long k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		dp[f[0].b].b=heap_len;

		push(dp[f[0].b].a,f[0].b);

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(heap[0].b != f[j].b && heap_len != 0) l1=heap[0].a;
			else
			{
				if(heap_len == 2) l1=heap[1].a;
				if(heap_len > 2) l1=max1(heap[1].a,heap[2].a);
			}

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

/*			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<" "<<l1<<" "<<k<<" "<<l<<endl;
*/
			k1=max1(k1,l1);

			if(dp[f[j].b].a == -LLONG_MAX) dp[f[j].b].a=k1,dp[f[j].b].b=heap_len,push(k1,f[j].b);
			else if(k1 > dp[f[j].b].a) dp[f[j].b].a=k1,rep(dp[f[j].b].b,k1);
		}

		heap_len=0;

		long long pr=-LLONG_MAX;

		for (int j=1;j<=n;j++) pr=max1(pr,dp[j].a);

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

long long maxx,maxx1;
long long ind,ind1;

struct bet
{
	long long a,b,c;
};
bet dp[100050],heap[100050];

struct bet1
{
	int a,b,c;
};
bet1 f[100050];

int main()
{
	scanf("%d %d",&n,&m);

	for (int i=0;i<n;i++) scanf("%d",&f[i].a);
	for (int i=0;i<n;i++) scanf("%d",&f[i].b);

	for (int i=0;i<m;i++)
	{long long k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		maxx=dp[f[0].b].a;ind=f[0].b;
		maxx1=-LLONG_MAX;

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(ind == f[j].b) l1=maxx1; else l1=maxx;

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

/*			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<" "<<l1<<" "<<k<<" "<<l<<endl;
*/
			k1=max1(k1,l1);

			if(maxx <= k1)
			{
				if(ind == f[j].b) maxx=k1;
				else {maxx1=maxx;ind1=ind;maxx=k1;ind=f[j].b;}
			}
			else if(k1 > maxx1) {maxx1=k1;ind1=f[j].b;}

			dp[f[j].b].a=max1(dp[f[j].b].a,k1);
		}

		heap_len=0;

		long long pr=maxx;

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

struct bet
{
	long long a,b,c;
};
bet dp[100050],heap[100050];

struct bet1
{
	int a,b,c;
};
bet1 f[100050];

void swap(int x, int y)
{
	bet t=heap[x];heap[x]=heap[y];heap[y]=t;

	long long t1=dp[heap[x].b].b;dp[heap[x].b].b=dp[heap[y].b].b;dp[heap[y].b].b=t1;
}

	void push(long long x, long long y)
	{
		heap[heap_len].a=x;heap[heap_len].b=y;

		long long s=heap_len;heap_len++;

		while(s>0)
		{
			if(heap[(s-1)/2].a < heap[s].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

	void rep(long long x, long long y)
	{
		heap[x].a=y;

		long long s=x;

		while(s>0)
		{
			if(heap[s].a>heap[(s-1)/2].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

int main()
{
	scanf("%d %d",&n,&m);

	for (int i=0;i<n;i++) scanf("%d",&f[i].a);
	for (int i=0;i<n;i++) scanf("%d",&f[i].b);

	for (int i=0;i<m;i++)
	{long long k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		dp[f[0].b].b=heap_len;

		push(dp[f[0].b].a,f[0].b);

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(heap[0].b != f[j].b && heap_len != 0) l1=heap[0].a;
			else
			{
				if(heap_len == 2) l1=heap[1].a;
				if(heap_len > 2) l1=max1(heap[1].a,heap[2].a);
			}

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

/*			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<" "<<l1<<" "<<k<<" "<<l<<endl;
*/
			k1=max1(k1,l1);

			if(dp[f[j].b].a == -LLONG_MAX) dp[f[j].b].a=k1,dp[f[j].b].b=heap_len,push(k1,f[j].b);
			else if(k1 > dp[f[j].b].a) dp[f[j].b].a=k1,rep(dp[f[j].b].b,k1);
		}

		heap_len=0;

		long long pr=-LLONG_MAX;

		for (int j=1;j<=n;j++) pr=max1(pr,dp[j].a);

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

struct bet
{
	long long a,b,c;
};
bet f[100050],dp[100050],heap[100050];

void swap(int x, int y)
{
	bet t=heap[x];heap[x]=heap[y];heap[y]=t;

	int t1=dp[heap[x].b].b;dp[heap[x].b].b=dp[heap[y].b].b;dp[heap[y].b].b=t1;
}

	void push(int x, int y)
	{
		heap[heap_len].a=x;heap[heap_len].b=y;

		int s=heap_len;heap_len++;

		while(s>0)
		{
			if(heap[(s-1)/2].a < heap[s].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

	void rep(int x, int y)
	{
		heap[x].a=y;

		int s=x;

		while(s>0)
		{
			if(heap[s].a>heap[(s-1)/2].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

int main()
{
	cin>>n>>m;

	for (int i=0;i<n;i++) cin>>f[i].a;
	for (int i=0;i<n;i++) cin>>f[i].b;

	for (int i=0;i<m;i++)
	{int k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		dp[f[0].b].b=heap_len;

		push(dp[f[0].b].a,f[0].b);

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(heap[0].b != f[j].b && heap_len != 0) l1=heap[0].a;
			else
			{
				if(heap_len == 2) l1=heap[1].a;
				if(heap_len > 2) l1=max1(heap[1].a,heap[2].a);
			}

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<""<<l1<<" "<<k<<" "<<l<<endl;

			k1=max1(k1,l1);

			if(dp[f[j].b].a == -LLONG_MAX) dp[f[j].b].a=k1,dp[f[j].b].b=heap_len,push(k1,f[j].b);
			else if(k1 > dp[f[j].b].a) dp[f[j].b].a=k1,rep(dp[f[j].b].b,k1);
		}

		heap_len=0;

		long long pr=-LLONG_MAX;

		for (int j=1;j<=n;j++) pr=max1(pr,dp[j].a);

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

struct bet
{
	long long a,b,c;
};
bet f[100050],dp[100050],heap[100050];

void swap(int x, int y)
{
	bet t=heap[x];heap[x]=heap[y];heap[y]=t;

	int t1=dp[heap[x].b].b;dp[heap[x].b].b=dp[heap[y].b].b;dp[heap[y].b].b=t1;
}

	void push(int x, int y)
	{
		heap[heap_len].a=x;heap[heap_len].b=y;

		int s=heap_len;heap_len++;

		while(s>0)
		{
			if(heap[(s-1)/2].a < heap[s].a) swap(s,(s-1)/2),s=(s-1)/2;
			else break;
		}
	}

	void rep(int x, int y)
	{
		heap[x].a=y;

		int s=x;

		while(s*2+1 < heap_len)
		{
			int k=s*2+1,l=s*2+2;

			if(heap[k].a<heap[l].a && l<heap_len) k=l;

			if(heap[k].a>heap[s].a) swap(s,k),s=k;
			else break;
		}
	}

int main()
{
	cin>>n>>m;

	for (int i=0;i<n;i++) cin>>f[i].a;
	for (int i=0;i<n;i++) cin>>f[i].b;

	for (int i=0;i<m;i++)
	{int k,l;
		cin>>k>>l;

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		dp[f[0].b].b=heap_len;

		push(dp[f[0].b].a,f[0].b);

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(heap[0].b != f[j].b && heap_len != 0) l1=heap[0].a;
			else
			{
				if(heap_len == 2) l1=heap[1].a;
				if(heap_len > 2) l1=max1(heap[1].a,heap[2].a);
			}

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

			//cout<<"--->"<<k1<<" "<<l1<<endl;

			k1=max1(k1,l1);

			if(dp[f[j].b].a == -LLONG_MAX) dp[f[j].b].a=k1,dp[f[j].b].b=heap_len,push(k1,f[j].b);
			else if(k1 > dp[f[j].b].a) dp[f[j].b].a=k1,rep(dp[f[j].b].b,k1);
		}

		heap_len=0;

		long long pr=-LLONG_MAX;

		for (int j=1;j<=n;j++) pr=max1(pr,dp[j].a);

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

long long maxx,maxx1;
long long ind,ind1;

struct bet
{
	long long a,b,c;
};
bet dp[100050],heap[100050];

struct bet1
{
	int a,b,c;
};
bet1 f[100050];

int main()
{
	scanf("%d %d",&n,&m);

	for (int i=0;i<n;i++) scanf("%d",&f[i].a);
	for (int i=0;i<n;i++) scanf("%d",&f[i].b);

	for (int i=0;i<m;i++)
	{long long k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		maxx=dp[f[0].b].a;ind=f[0].b;
		maxx1=-LLONG_MAX;

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(ind == f[j].b) l1=maxx1; else l1=maxx;

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

/*			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<" "<<l1<<" "<<k<<" "<<l<<endl;
*/
			k1=max1(k1,l1);

			if(maxx <= k1) {maxx1=maxx;ind1=ind;maxx=k1;ind=f[j].b;}
			else if(k1 > maxx1) {maxx=k1;ind1=f[j].b;}

			dp[f[j].b].a=max1(dp[f[j].b].a,k1);
		}

		heap_len=0;

		long long pr=maxx;

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


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

using namespace std;

# define min1(x,y) (x>y ? y : x)
# define max1(x,y) (x<y ? y : x)

int n,m,heap_len;

long long maxx,maxx1;
long long ind,ind1;

struct bet
{
	long long a,b,c;
};
bet dp[100050],heap[100050];

struct bet1
{
	int a,b,c;
};
bet1 f[100050];

int main()
{
	scanf("%d %d",&n,&m);

	for (int i=0;i<n;i++) scanf("%d",&f[i].a);
	for (int i=0;i<n;i++) scanf("%d",&f[i].b);

	for (int i=0;i<m;i++)
	{long long k,l;
		cin>>k>>l;

		//if(n == 100 && m == 2) {cout<<k<<" "<<l<<endl;continue;}

		for (int j=1;j<=n;j++) dp[j].a=-LLONG_MAX;

		dp[f[0].b].a=f[0].a*l;

		maxx=dp[f[0].b].a;ind=f[0].b;
		maxx1=-LLONG_MAX;

		for (int j=1;j<n;j++)
		{
			long long k1=f[j].a*l;

			if(dp[f[j].b].a != -LLONG_MAX)
			k1=max1(k1,dp[f[j].b].a+f[j].a*k);

			long long l1=-LLONG_MAX;

			if(ind == f[j].b) l1=maxx1; else l1=maxx;

			if(l1 != -LLONG_MAX) l1+=f[j].a*l;

/*			if(n == 100 && m == 2 && k1 > 0)
			cout<<"--->"<<k1<<" "<<l1<<" "<<k<<" "<<l<<endl;
*/
			k1=max1(k1,l1);

			if(maxx <= k1)
			{
				if(ind == f[j].b) maxx=k1;
				else maxx1=maxx;ind1=ind;maxx=k1;ind=f[j].b;
			}
			else if(k1 > maxx1) {maxx=k1;ind1=f[j].b;}

			dp[f[j].b].a=max1(dp[f[j].b].a,k1);
		}

		heap_len=0;

		long long pr=maxx;

		if(pr < 0) pr=0;

		cout<<pr<<endl;
	}

/*	int q=0;
	for (int jj=1;jj<=10;jj*=2)
	{
		for (int ii=q;ii<q+jj && ii<heap_len;ii++) printf("%d ",heap[ii].a);
		q+=jj;
		printf("\n");
	}
	*/
	getchar();getchar();
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

const int maxn = 2 * 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 9 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
pair<LL, int> mx[2];
LL maxv[maxn];
bool visit[maxn];

void maintain(int c)
{
    if(mx[0].second < 0) {
        mx[0].first = maxv[c], mx[0].second = c;
        return;
    }

    if(mx[1].second < 0 && mx[0].second != c) {
        mx[1].first = maxv[c], mx[1].second = c;
        return;
    }

    if(c != mx[0].second && c != mx[1].second) {        // null or inq
        if(maxv[c] >= mx[0].first) {
            swap(mx[0], mx[1]);
            mx[0].first = maxv[c], mx[0].second = c;
        } else if(maxv[c] >= mx[1].first) {
            mx[1].first = maxv[c], mx[1].second = c;
        }
    } else if(c == mx[0].second) {
        mx[0].first = max(maxv[c], mx[0].first);
    } else if(c == mx[1].second) {
        mx[1].first = max(maxv[c], mx[1].first);
    }
}

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        fill(maxv, maxv + colors, -INF);
        memset(visit, 0, sizeof(visit));
        mx[0].first = mx[1].first = -INF;
        mx[0].second = mx[1].second = -1;

        LL res = 0;
        for(int i = 0; i < n; ++i) {
            int c = color[i];

            LL t = val[i] * b;                  //only

            if(visit[c]) {               //same
                t = max(t, maxv[c] + val[i] * a);
            }

            if(mx[0].second >= 0) {           //diff
                if(mx[0].second != c) {
                    t = max(t, mx[0].first + val[i] * b);
                } else if(mx[1].second >= 0) {
                    t = max(t, mx[1].first + val[i] * b);
                }
            }

            if(!visit[c]) {
                visit[c] = true;
                maxv[c] = t;
            } else {
                maxv[c] = max(maxv[c], t);
            }

            res = max(res, t);
            maintain(c);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

/*
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
*/

const int maxn = 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 4 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
LL mx[maxn];

struct IntervalStree {
	int n;
	long long maxv[4*maxn + 10];

	void init(int n) {
	    this->n = n;
		initTree(0, 0, n - 1);
	}

	void initTree(int root, int rl, int rr) {
		if(rr == rl) {
			maxv[root] = -INF;
		} else {
			int rm = (rl + rr) >> 1;
			initTree(root * 2 + 1, rl, rm);
			initTree(root * 2 + 2, rm + 1, rr);
			maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
		}
	}

	long long query(int l, int r) { //[l, r]
		return internalQuery(0, 0, n - 1, l, r);
	}
	long long internalQuery(int root, int rl, int rr, int l, int r) {
		if(l > r) return -INF;

		if(rl == l && rr == r) {
			return maxv[root];
		}
		int rm = (rl + rr) >> 1;
		return max(internalQuery(root * 2 + 1, rl, rm, l, min(rm, r)), internalQuery(root * 2 + 2, rm + 1, rr, max(rm + 1, l), r));
	}

	void setValue(int k, int x) {
		internalSetValue(0, 0, n - 1, k, x);
	}
	void internalSetValue(int root, int rl, int rr, int k, int x) {
		if(rl == rr) {
			maxv[root] = x;
			return;
		}
		int rm = (rl + rr) >> 1;
		if(k <= rm) {
			internalSetValue(root * 2 + 1, rl, rm, k, x);
		} else {
			internalSetValue(root * 2 + 2, rm + 1, rr, k, x);
		}

		maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
	}
} tree;

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        fill(mx, mx + colors, -INF);

        tree.init(colors);
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL res = 0;

        mx[color[0]] = max(mx[color[0]], val[0] * b);
        tree.setValue(color[0], mx[color[0]]);

        res = max(res, mx[color[0]]);
        for(int i = 1; i < n; ++i) {
            LL t1, t2;
            t1 = val[i] * b;
            if(mx[color[i]] != INF) t1 = max(t1, mx[color[i]] + val[i] * a);

            t2 = -INF;
            if(color[i] > 0 && color[i] + 1 < colors)
                t2 = max(tree.query(0, color[i] - 1), tree.query(color[i] + 1, colors - 1));
            else if(color[i] > 0)
                t2 = tree.query(0, color[i] - 1);
            else if(color[i] + 1 < colors)
                t2 = tree.query(color[i] + 1, colors - 1);

            t2 += val[i] * b;
            mx[color[i]] = max(t1, t2);
            tree.setValue(color[i], mx[color[i]]);

            res = max(res, mx[color[i]]);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

const int maxn = 2 * 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 9 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
pair<LL, int> mx[2];
LL maxv[maxn];
bool visit[maxn];

void maintain(int c)
{
    if(maxv[c] > mx[0].first) {
        if(c == mx[0].second) {
            mx[0].first = maxv[c], mx[0].second = c;
        } else {
            swap(mx[0], mx[1]);
            mx[0].first = maxv[c], mx[0].second = c;
        }
    } else if(maxv[c] > mx[1].first && c != mx[0].first) {
        mx[1].first = maxv[c], mx[1].second = c;
    }
}

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);

        fill(maxv, maxv + colors, -INF);
        memset(visit, 0, sizeof(visit));

        mx[0].first = mx[1].first = -INF;
        mx[0].second = mx[1].second = -1;

        LL res = 0;
        for(int i = 0; i < n; ++i) {
            int c = color[i];

            LL t = val[i] * b;                  //only

            if(visit[c]) {               //same
                t = max(t, maxv[c] + val[i] * a);
            }

            if(mx[0].second != c) {
                t = max(t, mx[0].first + val[i] * b);
            } else if(mx[1].second >= 0) {
                t = max(t, mx[1].first + val[i] * b);
            }

            res = max(res, t);
            maxv[c] = max(maxv[c], t);
            visit[c] = true;

            maintain(c);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

const int maxn = 2 * 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 9 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
pair<LL, int> mx[2];
LL maxv[maxn];

void maintain(int c)
{
    if(c != mx[0].second && c != mx[1].second) {        // null or inq
        if(maxv[c] >= mx[0].first) {
            swap(mx[0], mx[1]);
            mx[0].first = maxv[c], mx[0].second = c;
        } else if(maxv[c] >= mx[1].first) {
            mx[1].first = maxv[c], mx[1].second = c;
        }
    } else if(c == mx[0].second) {
        mx[0].first = max(maxv[c], mx[0].first);
    } else if(c == mx[1].second) {
        mx[1].first = max(maxv[c], mx[1].first);
    }
}

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        fill(maxv, maxv + colors, -INF);
        mx[0].first = mx[1].first = -INF;
        mx[0].second = mx[1].second = -1;

        LL res = 0;
        for(int i = 0; i < n; ++i) {
            int c = color[i];

            LL t = val[i] * b;                  //only

            if(maxv[c] != -INF) {               //same
                t = max(t, maxv[c] + val[i] * a);
            }

            if(mx[0].first != -INF) {           //diff
                if(mx[0].second != c) {
                    t = max(t, mx[0].first + val[i] * b);
                } else if(mx[1].first != -INF) {
                    t = max(t, mx[1].first + val[i] * b);
                }
            }

            maxv[c] = max(maxv[c], t);
            res = max(res, t);
            maintain(c);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

const int maxn = 2 * 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 9 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
LL mx[maxn];

struct IntervalStree {
	int n;
	long long maxv[4*maxn + 10];

	void init(int n) {
	    this->n = n;
		initTree(0, 0, n - 1);
	}

	void initTree(int root, int rl, int rr) {
	    maxv[root] = -INF;

		if(rr == rl) {
			return;
		} else {
			int rm = (rl + rr) >> 1;
			initTree(root * 2 + 1, rl, rm);
			initTree(root * 2 + 2, rm + 1, rr);
		}
	}

	long long query(int l, int r) {
		return internalQuery(0, 0, n - 1, l, r);
	}
	long long internalQuery(int root, int rl, int rr, int l, int r) {
		if(l > r) return -INF;

		if(rl == l && rr == r) {
			return maxv[root];
		}
		int rm = (rl + rr) >> 1;
		return max(internalQuery(root * 2 + 1, rl, rm, l, min(rm, r)), internalQuery(root * 2 + 2, rm + 1, rr, max(rm + 1, l), r));
	}

	void setValue(int k, int x) {
		internalSetValue(0, 0, n - 1, k, x);
	}
	void internalSetValue(int root, int rl, int rr, int k, int x) {
		if(rl == rr) {
			maxv[root] = x;
			return;
		}
		int rm = (rl + rr) >> 1;
		if(k <= rm) {
			internalSetValue(root * 2 + 1, rl, rm, k, x);
		} else {
			internalSetValue(root * 2 + 2, rm + 1, rr, k, x);
		}

		maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
	}
} tree;

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL res = 0;

        for(int i = 0; i < colors; ++i) mx[i] = -INF;
        tree.init(colors);

        for(int i = 0; i < n; ++i) {
            LL t1, t2;

            t1 = val[i] * b;
            if(mx[color[i]] != -INF) t1 = max(t1, mx[color[i]] + val[i] * a);

            t2 = 0;
            LL tv = max(tree.query(0, color[i] - 1), tree.query(color[i] + 1, colors - 1));
            if(tv != -INF) t2 = tv + val[i] * b;

            mx[color[i]] = max(t1, t2);
            res = max(res, mx[color[i]]);

            tree.setValue(color[i], mx[color[i]]);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

const int maxn = 2 * 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 9 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
pair<LL, int> mx[2];
LL maxv[maxn];
bool visit[maxn];

void maintain(int c)
{
    if(maxv[c] >= mx[0].first) {
        if(c != mx[0].second) {
            mx[0].first = maxv[c], mx[0].second = c;
        } else {
            swap(mx[0], mx[1]);
            mx[0].first = maxv[c], mx[0].second = c;
        }
    } else if(maxv[c] >= mx[1].first && c != mx[0].first) {
        mx[1].first = maxv[c], mx[1].second = c;
    }
}

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        fill(maxv, maxv + colors, -INF);
        memset(visit, 0, sizeof(visit));
        mx[0].first = mx[1].first = -INF;
        mx[0].second = mx[1].second = -1;

        LL res = 0;
        for(int i = 0; i < n; ++i) {
            int c = color[i];

            LL t = val[i] * b;                  //only

            if(visit[c]) {               //same
                t = max(t, maxv[c] + val[i] * a);
            }

            if(mx[0].second >= 0) {           //diff
                if(mx[0].second != c) {
                    t = max(t, mx[0].first + val[i] * b);
                } else if(mx[1].second >= 0) {
                    t = max(t, mx[1].first + val[i] * b);
                }
            }

            maxv[c] = max(maxv[c], t);
            visit[c] = true;
            res = max(res, t);

            maintain(c);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

const int maxn = 2 * 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 9 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
LL mx[maxn];

struct IntervalStree {
	int n;
	long long maxv[4*maxn + 10];

	void init(int n) {
	    this->n = n;
		initTree(0, 0, n - 1);
	}

	void initTree(int root, int rl, int rr) {
	    maxv[root] = -INF;

		if(rr == rl) {
			return;
		} else {
			int rm = (rl + rr) >> 1;
			initTree(root * 2 + 1, rl, rm);
			initTree(root * 2 + 2, rm + 1, rr);
		}
	}

	long long query(int l, int r) {
		return internalQuery(0, 0, n - 1, l, r);
	}
	long long internalQuery(int root, int rl, int rr, int l, int r) {
		if(l > r) return -INF;

		if(rl == l && rr == r) {
			return maxv[root];
		}
		int rm = (rl + rr) >> 1;
		return max(internalQuery(root * 2 + 1, rl, rm, l, min(rm, r)), internalQuery(root * 2 + 2, rm + 1, rr, max(rm + 1, l), r));
	}

	void setValue(int k, int x) {
		internalSetValue(0, 0, n - 1, k, x);
	}
	void internalSetValue(int root, int rl, int rr, int k, int x) {
		if(rl == rr) {
			maxv[root] = x;
			return;
		}
		int rm = (rl + rr) >> 1;
		if(k <= rm) {
			internalSetValue(root * 2 + 1, rl, rm, k, x);
		} else {
			internalSetValue(root * 2 + 2, rm + 1, rr, k, x);
		}

		maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
	}
} tree;

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL res = 0;

        for(int i = 0; i < colors; ++i) mx[i] = -INF;
        tree.init(colors);

        for(int i = 0; i < n; ++i) {
            LL t1; // only, same, diff

            t1 = val[i] * b; // only
            if(mx[color[i]] != -INF) t1 = max(t1, mx[color[i]] + val[i] * a); // same

            LL tv = max(tree.query(0, color[i] - 1), tree.query(color[i] + 1, colors - 1));
            if(tv != -INF) t1 = max(t1, tv + val[i] * b);                       // diff

            mx[color[i]] = max(t1, mx[color[i]]);
            res = max(res, mx[color[i]]);

            tree.setValue(color[i], mx[color[i]]);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

/*
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
*/

const int maxn = 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 4 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
LL mx[maxn];

struct IntervalStree {
	int n;
	long long maxv[4*maxn + 10];

	void init(int n) {
	    this->n = n;
		initTree(0, 0, n - 1);
	}

	void initTree(int root, int rl, int rr) {
	    maxv[root] = -INF;

		if(rr == rl) {
			return;
		} else {
			int rm = (rl + rr) >> 1;
			initTree(root * 2 + 1, rl, rm);
			initTree(root * 2 + 2, rm + 1, rr);
		}
	}

	long long query(int l, int r) {
		return internalQuery(0, 0, n - 1, l, r);
	}
	long long internalQuery(int root, int rl, int rr, int l, int r) {
		if(l > r) return -INF;

		if(rl == l && rr == r) {
			return maxv[root];
		}
		int rm = (rl + rr) >> 1;
		return max(internalQuery(root * 2 + 1, rl, rm, l, min(rm, r)), internalQuery(root * 2 + 2, rm + 1, rr, max(rm + 1, l), r));
	}

	void setValue(int k, int x) {
		internalSetValue(0, 0, n - 1, k, x);
	}
	void internalSetValue(int root, int rl, int rr, int k, int x) {
		if(rl == rr) {
			maxv[root] = x;
			return;
		}
		int rm = (rl + rr) >> 1;
		if(k <= rm) {
			internalSetValue(root * 2 + 1, rl, rm, k, x);
		} else {
			internalSetValue(root * 2 + 2, rm + 1, rr, k, x);
		}

		maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
	}
} tree;

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL res = 0;

        fill(mx, mx + colors, -INF);
        tree.init(colors);

        for(int i = 0; i < n; ++i) {
            LL t1, t2;

            t1 = val[i] * b;
            if(mx[color[i]] != -INF) t1 = max(t1, mx[color[i]] + val[i] * a);

            t2 = -INF;
            if(color[i] > 0 && color[i] + 1 < colors)
                t2 = max(tree.query(0, color[i] - 1), tree.query(color[i] + 1, colors - 1));
            else if(color[i] > 0)
                t2 = tree.query(0, color[i] - 1);
            else if(color[i] + 1 < colors)
                t2 = tree.query(color[i] + 1, colors - 1);

            t2 += val[i] * b;
            mx[color[i]] = max(t1, t2);
            tree.setValue(color[i], mx[color[i]]);

            res = max(res, mx[color[i]]);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

/*
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
*/

const int maxn = 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 4 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
LL mx[maxn];

struct IntervalStree {
	int n;
	long long maxv[4*maxn + 10];

	void init(int n) {
	    this->n = n;
		initTree(0, 0, n - 1);
	}

	void initTree(int root, int rl, int rr) {
	    maxv[root] = -INF;

		if(rr == rl) {
			return;
		} else {
			int rm = (rl + rr) >> 1;
			initTree(root * 2 + 1, rl, rm);
			initTree(root * 2 + 2, rm + 1, rr);
		}
	}

	long long query(int l, int r) {
		return internalQuery(0, 0, n - 1, l, r);
	}
	long long internalQuery(int root, int rl, int rr, int l, int r) {
		if(l > r) return -INF;

		if(rl == l && rr == r) {
			return maxv[root];
		}
		int rm = (rl + rr) >> 1;
		return max(internalQuery(root * 2 + 1, rl, rm, l, min(rm, r)), internalQuery(root * 2 + 2, rm + 1, rr, max(rm + 1, l), r));
	}

	void setValue(int k, int x) {
		internalSetValue(0, 0, n - 1, k, x);
	}
	void internalSetValue(int root, int rl, int rr, int k, int x) {
		if(rl == rr) {
			maxv[root] = x;
			return;
		}
		int rm = (rl + rr) >> 1;
		if(k <= rm) {
			internalSetValue(root * 2 + 1, rl, rm, k, x);
		} else {
			internalSetValue(root * 2 + 2, rm + 1, rr, k, x);
		}

		maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
	}
} tree;

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL res = 0;

        fill(mx, mx + colors, -INF);
        tree.init(colors);

        for(int i = 0; i < n; ++i) {
            LL t1, t2;

            t1 = val[i] * b;
            if(mx[color[i]] != -INF) t1 = max(t1, mx[color[i]] + val[i] * a);

            t2 = val[i] * b;
            if(color[i] > 0 && color[i] + 1 < colors) {
                LL val = max(tree.query(0, color[i] - 1), tree.query(color[i] + 1, colors - 1));
                if(val != -INF) t2 += val;
            } else if(color[i] > 0) {
                LL val = tree.query(0, color[i] - 1);
                if(val != -INF) t2 += val;
            }
            else if(color[i] + 1 < colors) {
                LL val = tree.query(color[i] + 1, colors - 1);
                if(val != -INF) t2 += val;
            }

            mx[color[i]] = max(t1, t2);
            tree.setValue(color[i], mx[color[i]]);

            res = max(res, mx[color[i]]);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

/*
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
*/

const int maxn = 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 9 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
LL mx[maxn];

struct IntervalStree {
	int n;
	long long maxv[4*maxn + 10];

	// ����data��ʼ��һ���߶�����data����ݸ���Ϊn�������������[0, n-1]
	void init(int n) {
	    this->n = n;
		initTree(0, 0, n - 1);
	}

	// ��ʼ�����[rl, rr]���������[rl, rr]�Ľ����Ϊroot
	void initTree(int root, int rl, int rr) { //[rl, rr]
		if(rr == rl) {
			maxv[root] = mx[rl];
		} else {
			int rm = (rl + rr) >> 1;
			initTree(root * 2 + 1, rl, rm);
			initTree(root * 2 + 2, rm + 1, rr);
			maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
		}
	}

	// ��ѯ[l, r]��ֵ��l��r��ȡֵ��Χ��[0, n - 1]
	long long query(int l, int r) { //[l, r]
		return internalQuery(0, 0, n - 1, l, r);
	}
	// ��ѯ[l, r]��[rl, rr]�ཻ��ֵ�����У����[rl, rr]�Ľ����Ϊroot
	long long internalQuery(int root, int rl, int rr, int l, int r) {
		if(l > r) return -INF;

		if(rl == l && rr == r) {
			return maxv[root];
		}
		int rm = (rl + rr) >> 1;
		return max(internalQuery(root * 2 + 1, rl, rm, l, min(rm, r)), internalQuery(root * 2 + 2, rm + 1, rr, max(rm + 1, l), r));
	}

	// ���±�Ϊk��Ԫ������Ϊx��k��ȡֵ��Χ��[0, n - 1]
	void setValue(int k, int x) {
		internalSetValue(0, 0, n - 1, k, x);
	}
	// ��[rl, rr]��k�ཻ�ĵ��ֵ����Ϊx�����У����[rl, rr]�Ľ����Ϊrott
	void internalSetValue(int root, int rl, int rr, int k, int x) {
		if(rl == rr) {
			maxv[root] = x;
			return;
		}
		int rm = (rl + rr) >> 1;
		if(k <= rm) {
			internalSetValue(root * 2 + 1, rl, rm, k, x);
		} else {
			internalSetValue(root * 2 + 2, rm + 1, rr, k, x);
		}

		maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
	}
} tree;

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        fill(mx, mx + colors, -INF);

        tree.init(colors);
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL res = 0;
        // first one;
        mx[color[0]] = max(mx[color[0]], val[0] * b);
        tree.setValue(color[0], mx[color[0]]);

        res = max(res, mx[color[0]]);
        for(int i = 1; i < n; ++i) {
            LL t1, t2;
            t1 = val[i] * b;
            if(mx[color[i]] != INF) t1 = max(t1, mx[color[i]] + val[i] * a);

            if(color[i] > 0 && color[i] + 1 < colors)
                t2 = max(tree.query(0, color[i] - 1), tree.query(color[i] + 1, colors - 1));
            else if(color[i] > 0)
                t2 = tree.query(0, color[i] - 1);
            else
                t2 = tree.query(color[i] + 1, colors - 1);

            t2 += val[i] * b;
            mx[color[i]] = max(t1, t2);
            tree.setValue(color[i], mx[color[i]]);

            res = max(res, mx[color[i]]);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

using namespace std;
typedef long long ll;
const int MAXN = 100100;
const ll INF = 1e16;

int N, Q;
ll val[MAXN];
int color[MAXN];
ll A, B;

bool seen[MAXN]; // if color i is seen
ll bcolor[MAXN]; // best of color [i]
ll b1, b2;
int c1, c2; //values and colors of the top 2 best with diff colors

void solve()
{
	for (int i = 0; i < MAXN; i++)
	{
		seen[i] = false;
		bcolor[i] = -INF;
	}
	b1 = b2 = -INF;
	c1 = c2 = -1;

	ll ans = 0;

	for (int i = 0; i < N; i++)
	{
		ll aval = B * val[i];
		if (seen[color[i]])
			aval = max (aval, bcolor[color[i]] + A * val[i]);
		if (c1 != color[i])
			aval = max (aval, b1 + B * val[i]);
		else
			aval = max (aval, b2 + B * val[i]);

		ans = max (ans, aval);

		bcolor[color[i]] = max (aval, bcolor[color[i]]);
		seen[color[i]] = true;

		if (aval > b1)
		{
			if (c1 == color[i])
			{
				b1 = aval;
				c1 = color[i];
			}
			else
			{
				b2 = b1;
				c2 = c1;
				b1 = aval;
				c1 = color[i];
			}
		}
		else if (aval > b2 && color[i] != c1)
		{
			b2 = aval;
			c2 = color[i];
		}
	}

	cout << ans << "\n";
}

int main()
{
	cin >> N >> Q;
	for (int i = 0; i < N; i++)
		cin >> val[i];
	for (int i = 0; i < N; i++)
		cin >> color[i];

	for (int i = 0; i < Q; i++)
	{
		cin >> A >> B;
		solve();
	}

	return 0;
}


//#include <bits/stdc++.h>

#ifdef DEBUG
    #define I64d lld
#endif // DEBUG

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>

#include <cstdio>
#include <ctime>
#include <cmath>

#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;

/*
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
*/

const int maxn = 1e5 + 15;
const int mod = 1000000007;
const int inf = 1e9 + 10;
const LL INF = 9 * 1e18;
typedef pair<int, int> P;
#define MP(x, y) make_pair(x, y)
#define endl "\n"

int n, q;
int val[maxn], color[maxn], cid[maxn], colors;
LL mx[maxn];

struct IntervalStree {
	int n;
	long long maxv[4*maxn + 10];

	// ����data��ʼ��һ���߶�����data����ݸ���Ϊn�������������[0, n-1]
	void init(int n) {
	    this->n = n;
		initTree(0, 0, n - 1);
	}

	// ��ʼ�����[rl, rr]���������[rl, rr]�Ľ����Ϊroot
	void initTree(int root, int rl, int rr) { //[rl, rr]
		if(rr == rl) {
			maxv[root] = mx[rl];
		} else {
			int rm = (rl + rr) >> 1;
			initTree(root * 2 + 1, rl, rm);
			initTree(root * 2 + 2, rm + 1, rr);
			maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
		}
	}

	// ��ѯ[l, r]��ֵ��l��r��ȡֵ��Χ��[0, n - 1]
	long long query(int l, int r) { //[l, r]
		return internalQuery(0, 0, n - 1, l, r);
	}
	// ��ѯ[l, r]��[rl, rr]�ཻ��ֵ�����У����[rl, rr]�Ľ����Ϊroot
	long long internalQuery(int root, int rl, int rr, int l, int r) {
		if(l > r) return 0;

		if(rl == l && rr == r) {
			return maxv[root];
		}
		int rm = (rl + rr) >> 1;
		return internalQuery(root * 2 + 1, rl, rm, l, min(rm, r)) + internalQuery(root * 2 + 2, rm + 1, rr, max(rm + 1, l), r);
	}

	// ���±�Ϊk��Ԫ������Ϊx��k��ȡֵ��Χ��[0, n - 1]
	void setValue(int k, int x) {
		internalSetValue(0, 0, n - 1, k, x);
	}
	// ��[rl, rr]��k�ཻ�ĵ��ֵ����Ϊx�����У����[rl, rr]�Ľ����Ϊrott
	void internalSetValue(int root, int rl, int rr, int k, int x) {
		if(rl == rr) {
			maxv[root] = x;
			return;
		}
		int rm = (rl + rr) >> 1;
		if(k <= rm) {
			internalSetValue(root * 2 + 1, rl, rm, k, x);
		} else {
			internalSetValue(root * 2 + 2, rm + 1, rr, k, x);
		}

		maxv[root] = max(maxv[root * 2 + 1], maxv[root * 2 + 2]);
	}
} tree;

int MAIN()
{
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; ++i) scanf("%d", &val[i]);
    memset(cid, -1, sizeof(cid));
    for(int i = 0; i < n; ++i) {
        int c;
        scanf("%d", &c);
        if(cid[c] < 0) cid[c] = colors++;
        color[i] = cid[c];
    }
    while(q--) {
        fill(mx, mx + colors, -INF);

        tree.init(colors);
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL res = 0;
        // first one;
        mx[color[0]] = max(mx[color[0]], val[0] * b);
        tree.setValue(color[0], mx[color[0]]);

        res = max(res, mx[color[0]]);
        for(int i = 1; i < n; ++i) {
            LL t1, t2;
            t1 = val[i] * b;
            if(mx[color[i]] != INF) t1 = max(t1, mx[color[i]] + val[i] * a);

            if(color[i] > 0 && color[i] + 1 < colors)
                t2 = max(tree.query(0, color[i] - 1), tree.query(color[i] + 1, colors - 1));
            else if(color[i] > 0)
                t2 = tree.query(0, color[i] - 1);
            else
                t2 = tree.query(color[i] + 1, colors - 1);

            t2 += val[i] * b;
            mx[color[i]] = max(t1, t2);
            tree.setValue(color[i], mx[color[i]]);

            res = max(res, mx[color[i]]);
        }
        printf("%I64d\n", res);
    }
    return 0;
}

int main()
{
#ifdef DEBUG
    freopen("data.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cout << fixed << setprecision(16);

    int ret = MAIN();

#ifdef DEBUG
    cout << "Time elapsed: " << 1000*clock()/CLOCKS_PER_SEC <<" ms" << endl;
#endif
    return ret;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000000LL;

void solve() {
    ll max1 = -inf, max2 = -inf;
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc = b*v[i];

        if(max1 > -inf && col1 != c[i]) {
            maxc = max(maxc, max1 + b*v[i]);
        }

        if(max2 > -inf && col2 != c[i]) {
            maxc = max(maxc, max2 + b*v[i]);
        }

        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }

        mx[c[i]] = max(mx[c[i]], maxc);

        if(col2 == c[i]) {
            max2 = max(max2, maxc);
        }
        if(col1 == c[i]) {
            max1 = max(max1, maxc);
        }

        if(maxc > max2) {
            max2 = maxc;
            col2 = c[i];
        }
        if(max1 < max2) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max(0LL,max1));
}

int main() {
//  freopen("input.in", "r", stdin);
    cin >> n >> q;
    for(int i = 0; i < n; i++) {
        scanf("%d", v+i);
    }
    for(int i = 0; i < n; i++) {
        scanf("%d", c+i);
    }

    for(int i = 0; i < q; i++) {
        scanf("%I64d %I64d", &a, &b);
        solve();
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000000LL;

void solve() {
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }

    ll max1 = 0, max2 = 0;
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc;
        if(col1 != c[i]) {
            maxc = max1 + b*v[i];
        } else {
            maxc = max2 + b*v[i];
        }
        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }
        mx[c[i]] = max(maxc, mx[c[i]]);
        if(col1 == c[i]) {
            max1 = max(max1, maxc);
        } else if(col2 == c[i]) {
            max2 = max(max2, maxc);
        } else if(max1 < maxc) {
            max1 = maxc;
            col1 = c[i];
        } else if(max2 < maxc) {
            max2 = maxc;
            col2 = c[i];
        }

        if(col1 != 0 && col1 == col2) {
            cout << "LOL" << endl;
            return;
        }

        if(max2 > max1) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max1);
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> q) {
        for(int i = 0; i < n; i++) {
            scanf("%d", v+i);
        }
        for(int i = 0; i < n; i++) {
            scanf("%d", c+i);
        }

        for(int i = 0; i < q; i++) {
            scanf("%I64d %I64d", &a, &b);
            solve();
        }
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000000LL;

void solve() {
    ll max1 = -inf, max2 = -inf;
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc = b*v[i];

        if(max1 > -inf && col1 != c[i]) {
            maxc = max(maxc, max1 + b*v[i]);
        }

        if(max2 > -inf && col2 != c[i]) {
            maxc = max(maxc, max2 + b*v[i]);
        }

        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }

        mx[c[i]] = max(mx[c[i]], maxc);

        if(maxc > max2) {
            max2 = maxc;
            col2 = c[i];
        }
        if(max1 < max2) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max(0LL,max1));
}

int main() {
//  freopen("input.in", "r", stdin);
    cin >> n >> q;
    for(int i = 0; i < n; i++) {
        scanf("%d", v+i);
    }
    for(int i = 0; i < n; i++) {
        scanf("%d", c+i);
    }

    for(int i = 0; i < q; i++) {
        scanf("%I64d %I64d", &a, &b);
        solve();
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000000LL;

void solve() {
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }

    ll max1 = 0, max2 = 0;
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc;
        if(col1 != c[i]) {
            maxc = max1 + b*v[i];
        } else {
            maxc = max2 + b*v[i];
        }
        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }
        mx[c[i]] = max(maxc, mx[c[i]]);
        if(col1 == c[i]) {
            max1 = max(max1, maxc);
        } else if(col2 == c[i]) {
            max2 = max(max2, maxc);
        } else if(max1 < maxc) {
            max2 = max1;
            col2 = col1;
            max1 = maxc;
            col1 = c[i];
        } else if(max2 < maxc) {
            max2 = maxc;
            col2 = c[i];
        }
        if(max2 > max1) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max1);
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> q) {
        for(int i = 0; i < n; i++) {
            scanf("%d", v+i);
        }
        for(int i = 0; i < n; i++) {
            scanf("%d", c+i);
        }

        for(int i = 0; i < q; i++) {
            scanf("%I64d %I64d", &a, &b);
            solve();
        }
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000000LL;

void solve() {
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }

    ll max1 = 0, max2 = 0;
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc;
        if(col1 != c[i]) {
            maxc = max1 + b*v[i];
        } else {
            maxc = max2 + b*v[i];
        }
        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }
        mx[c[i]] = max(maxc, mx[c[i]]);
        if(col1 == c[i]) {
            max1 = max(max1, maxc);
        } else if(col2 == c[i]) {
            max2 = max(max2, maxc);
        } else if(max1 < maxc) {
            max1 = maxc;
            col1 = c[i];
        } else if(max2 < maxc) {
            max2 = maxc;
            col2 = c[i];
        }

        if(max2 > max1) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max1);
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> q) {
        for(int i = 0; i < n; i++) {
            scanf("%d", v+i);
        }
        for(int i = 0; i < n; i++) {
            scanf("%d", c+i);
        }

        for(int i = 0; i < q; i++) {
            scanf("%I64d %I64d", &a, &b);
            solve();
        }
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000000LL;

void solve() {
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }

    ll max1 = 0, max2 = 0;
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc;
        if(max1 != c[i]) {
            maxc = max1 + b*v[i];
        } else {
            maxc = max2 + b*v[i];
        }
        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }
        mx[c[i]] = max(maxc, mx[c[i]]);
        if(col1 == c[i]) {
            max1 = max(max1, maxc);
        } else if(col2 == c[i]) {
            max2 = max(max2, maxc);
        } else if(max1 < maxc) {
            max1 = maxc;
            col1 = c[i];
        } else if(max2 < maxc) {
            max2 = maxc;
            col2 = c[i];
        }

        if(max2 > max1) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max1);
}

int main() {
//  freopen("input.in", "r", stdin);
    cin >> n >> q;
    for(int i = 0; i < n; i++) {
        scanf("%d", v+i);
    }
    for(int i = 0; i < n; i++) {
        scanf("%d", c+i);
    }

    for(int i = 0; i < q; i++) {
        scanf("%I64d %I64d", &a, &b);
        solve();
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000LL;

void solve() {
    ll max1 = -inf, max2 = -inf;
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc = b*v[i];

        if(col1 == c[i]) {
            maxc = max(maxc, max1 + a*v[i]);
        } else {
            maxc = max(maxc, max1 + b*v[i]);
        }

        if(col2 == c[i]) {
            maxc = max(maxc, max2 + a*v[i]);
        } else {
            maxc = max(maxc, max2 + b*v[i]);
        }

        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }
        mx[c[i]] = max(mx[c[i]], maxc);

        if(maxc > max2) {
            max2 = maxc;
            col2 = c[i];
        }
        if(max1 < max2) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max1);
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> q) {
        for(int i = 0; i < n; i++) {
            scanf("%d", v+i);
        }
        for(int i = 0; i < n; i++) {
            scanf("%d", c+i);
        }

        for(int i = 0; i < q; i++) {
            scanf("%I64d %I64d", &a, &b);
            solve();
        }
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000LL;

void solve() {
    ll max1 = -inf, max2 = -inf;
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc = b*v[i];

        if(col1 == c[i]) {
            maxc = max(maxc, max1 + a*v[i]);
        } else {
            maxc = max(maxc, max1 + b*v[i]);
        }

        if(col2 == c[i]) {
            maxc = max(maxc, max2 + a*v[i]);
        } else {
            maxc = max(maxc, max2 + b*v[i]);
        }

        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }
        mx[c[i]] = max(mx[c[i]], maxc);

        if(maxc > max2) {
            max2 = maxc;
            col2 = c[i];
        }
        if(max1 < max2) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max(0,max1));
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> q) {
        for(int i = 0; i < n; i++) {
            scanf("%d", v+i);
        }
        for(int i = 0; i < n; i++) {
            scanf("%d", c+i);
        }

        for(int i = 0; i < q; i++) {
            scanf("%I64d %I64d", &a, &b);
            solve();
        }
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b;

void solve() {
    ll max1 = -1000000000000LL, max2 = -1000000000000LL;
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc = b*v[i];

        if(col1 == c[i]) {
            maxc = max(maxc, max1 + a*v[i]);
        } else {
            maxc = max(maxc, max1 + b*v[i]);
        }

        if(col2 == c[i]) {
            maxc = max(maxc, max2 + a*v[i]);
        } else {
            maxc = max(maxc, max2 + b*v[i]);
        }

        if(maxc > max2) {
            max2 = maxc;
            col2 = c[i];
        }
        if(max1 < max2) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max1);
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> q) {
        for(int i = 0; i < n; i++) {
            scanf("%d", v+i);
        }
        for(int i = 0; i < n; i++) {
            scanf("%d", c+i);
        }

        for(int i = 0; i < q; i++) {
            scanf("%I64d %I64d", &a, &b);
            solve();
        }
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000000LL;

void solve() {
    ll max1 = -inf, max2 = -inf;
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc = b*v[i];

        if(max1 > -inf && col1 != c[i]) {
            maxc = max(maxc, max1 + b*v[i]);
        }

        if(max2 > -inf && col2 != c[i]) {
            maxc = max(maxc, max2 + b*v[i]);
        }

        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }

        mx[c[i]] = max(mx[c[i]], maxc);

        if(maxc > max2) {
            max2 = maxc;
            col2 = c[i];
        }
        if(max1 < max2) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max(0LL,max1));
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> q) {
        for(int i = 0; i < n; i++) {
            scanf("%d", v+i);
        }
        for(int i = 0; i < n; i++) {
            scanf("%d", c+i);
        }

        for(int i = 0; i < q; i++) {
            scanf("%I64d %I64d", &a, &b);
            solve();
        }
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<vector<int> > graph;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

#define MAXN 100005

int n, q, v[MAXN], c[MAXN];
ll a, b, mx[MAXN];

ll inf = 1000000000000LL;

void solve() {
    ll max1 = -inf, max2 = -inf;
    for(int i = 0; i < MAXN; i++) {
        mx[i] = -inf;
    }
    int col1 = 0, col2 = 0;
    for(int i = 0; i < n; i++) {
        ll maxc = b*v[i];

        if(col1 == c[i]) {
            maxc = max(maxc, max1 + a*v[i]);
        } else {
            maxc = max(maxc, max1 + b*v[i]);
        }

        if(col2 == c[i]) {
            maxc = max(maxc, max2 + a*v[i]);
        } else {
            maxc = max(maxc, max2 + b*v[i]);
        }

        if(mx[c[i]] > -inf) {
            maxc = max(maxc, mx[c[i]] + a*v[i]);
        }
        mx[c[i]] = max(mx[c[i]], maxc);

        if(maxc > max2) {
            max2 = maxc;
            col2 = c[i];
        }
        if(max1 < max2) {
            swap(max1, max2);
            swap(col1, col2);
        }
    }

    printf("%I64d\n", max(0LL,max1));
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> q) {
        for(int i = 0; i < n; i++) {
            scanf("%d", v+i);
        }
        for(int i = 0; i < n; i++) {
            scanf("%d", c+i);
        }

        for(int i = 0; i < q; i++) {
            scanf("%I64d %I64d", &a, &b);
            solve();
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		memset(dp,0,sizeof(dp));
		memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			if(vis[col[i]]==0)
				dp[col[i]]=max(dp[col[i]],dp[col[i]]+b*val[i]);
			else
				dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);

			vis[col[i]]=1;

			if(col[ind1]!=col[i])
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}
		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		memset(dp,0,sizeof(dp));
		memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			if(vis[col[i]]!=0)
				dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);    // same as previous
			dp[col[i]]=max(dp[col[i]],b*val[i]);               //  beginning

			vis[col[i]]=1;

			if(col[ind1]!=col[i]&&(ind1))
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else if(ind2)
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		for(int j=0;j<502;j++)
			dp[j]=-1000000000000ll;
		memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			//if(vis[col[i]]!=0)
			dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);    // same as previous
			dp[col[i]]=max(dp[col[i]],b*val[i]);                   //  beginning

			//vis[col[i]]=1;

			if(col[ind1]!=col[i]&&(ind1))
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else if(ind2)
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
				continue;
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		memset(dp,0,sizeof(dp));
		memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			if(vis[col[i]]==0)
				dp[col[i]]=max(dp[col[i]],dp[col[i]]+b*val[i]);
			else
				dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);

			vis[col[i]]=1;

			if(col[ind1]!=col[i])
			{
				if(max1+b*val[i]>dp[col[i]])
				{
					dp[col[i]]=max1+b*val[i];
					max3=dp[col[i]];
					ind3=i;

					if(max3>max2)
					{
						swap(max3,max2);
						swap(ind3,ind2);
					}
					if(max2>max1)
					{
						swap(max1,max2);
						swap(ind1,ind2);
					}
				}
			}
			else
			{
				if(max2+b*val[i]>dp[col[i]])
				{
					dp[col[i]]=max2+b*val[i];
					max2=dp[col[i]];
					ind2=i;

					if(max2>max1)
					{
						swap(max1,max2);
						swap(ind1,ind2);
					}
				}
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

			/*for(int j=1;j<=3;j++)
				cout<<dp[j]<<" ";
			cout<<endl;
			cout<<max1<<" "<<max2<<" "<<ind1<<" "<<ind2<<" naya "<<endl;*/
		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		memset(dp,0,sizeof(dp));
		memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			if(vis[col[i]]!=0)
				dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);    // same as previous
			dp[col[i]]=max(dp[col[i]],b*val[i]);               //  beginning

			vis[col[i]]=1;

			if(col[ind1]!=col[i]&&(ind1))
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else if(ind2)
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
				continue;
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		for(int j=0;j<502;j++)
			dp[j]=-1000000000000ll;
		memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			//if(vis[col[i]]!=0)
			dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);    // same as previous
			//dp[col[i]]=max(dp[col[i]],b*val[i]);                   //  beginning

			//vis[col[i]]=1;

			if(col[ind1]!=col[i])
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
				continue;
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		for(int j=0;j<502;j++)
			dp[j]=-1000000000000ll;
		memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			//if(vis[col[i]]!=0)
			dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);    // same as previous
			dp[col[i]]=max(dp[col[i]],b*val[i]);                   //  beginning

			//vis[col[i]]=1;

			if(col[ind1]!=col[i]&&(ind1))
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else if(ind2)
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		for(int j=0;j<502;j++)
			dp[j]=-1000000000000ll;
		//memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			//if(vis[col[i]]!=0)
			dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);    // same as previous
			//dp[col[i]]=max(dp[col[i]],b*val[i]);                   //  beginning

			//vis[col[i]]=1;

			if(col[ind1]!=col[i]&&(ind1))
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else if(ind2)
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

		}
		cout<<max1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,q,col[100005],val[100005],vis[505],a,b,max1,max2,max3,ind1,ind2,ind3,dp[505];
int main()
{
	cin>>n>>q;
	col[0]=0;

	for(int i=1;i<=n;i++)
		cin>>val[i];
	for(int i=1;i<=n;i++)
		cin>>col[i];

	while(q--)
	{
		for(int j=0;j<502;j++)
			dp[j]=-1000000000000ll;
		//memset(vis,0,sizeof(vis));
		cin>>a>>b;
		max1=0;max2=0;
		ind1=0;ind2=0;

		for(int i=1;i<=n;i++)
		{
			dp[col[i]]=0;
			//if(vis[col[i]]!=0)
			dp[col[i]]=max(dp[col[i]],dp[col[i]]+a*val[i]);    // same as previous
			dp[col[i]]=max(dp[col[i]],b*val[i]);                   //  beginning

			//vis[col[i]]=1;

			if(col[ind1]!=col[i]&&(ind1))
			{
				if(max1+b*val[i]>dp[col[i]])
					dp[col[i]]=max1+b*val[i];
			}
			else if(ind2)
			{
				if(max2+b*val[i]>dp[col[i]])
					dp[col[i]]=max2+b*val[i];
				continue;
			}

			max3=dp[col[i]];
			ind3=i;

			if(max3>max2)
			{
				swap(max3,max2);
				swap(ind3,ind2);
			}
			if(max2>max1)
			{
				swap(max1,max2);
				swap(ind1,ind2);
			}

		}
		cout<<max1<<endl;
	}
	return 0;
}