/*
TASK:skok
LANG:C++
*/

#include <iostream>
#include <cstdio>
using namespace std;

int n,m;
int mas[200001],best[200001],num[200001],jump[200];
int bst;
int ind;

void read()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>jump[i];
	}
	for(int i=0;i<=n;i++)
	{
		scanf("%d",&mas[i]);
	}
}

int main()
{
	read();
	best[0]=mas[0];
	bst=best[0];
	num[0]=1;
	for(int i=1;i<=n;i++)
	{
		int max=0,k=0;
		for(int j=0;j<m;j++)
		{
			if(i-jump[j]>=0&&num[i-jump[j]])
			{
				k=1;
				if(max<=best[i-jump[j]]) 
				{
					max=best[i-jump[j]];
				}
			}
		}
		best[i]=max+mas[i];
		if(k)
		{
			num[i]=1;
			if(bst<best[i])
			{
				bst=best[i];
				ind=i;
			}
			if(bst==best[i]&&i<ind)
			{
				bst=best[i];
				ind=i;
			}
		}
	}
	cout<<bst<<' '<<ind<<endl;
	return 0;
}
