/*
TASK:skok
LANG:C++
*/
#include <iostream>
#include <algorithm>
using namespace std;
int a[200000];                    // lane
int b[100];                       // types of jumps
unsigned long long int n;         // number of tiles
int m;                            // number of types of jumps
unsigned long long int sum=0;     // tekushta
unsigned long long int best[2]={0,0};   // best

void write(int tile)
{
     if(sum==best[0])
       if(tile<best[1])
          best[1]=tile;
                                   
     if(sum>best[0])
     {
       best[0]=sum;
       best[1]=tile;
     }
}

void jump(unsigned long long int tile)
{        
        for(int i=0; i<m; i++)
        {
            if(b[i]==1001) continue;
            sum+=a[tile];
            if((tile+b[i])>=n)
            {
               write(tile);
               sum-=a[tile];
               return;
            }
            jump(tile+b[i]);
            sum-=a[tile];
        }
}

bool cmp(int x, int y)
{return x<y;}

int main()
{
    unsigned long long int i;
    cin >> n >> m;
    for(i=0; i<m; i++) cin >> b[i];
    for(i=0; i<=n; i++) cin >> a[i];
   
    sort(b, b+m, cmp);
    
    for(i=0; i<m-1; i++)
    {
      if(b[i]==1001) continue;
      for(int j=i+1; j<m; j++)
      {
         if(b[j]==1001) continue;
         if(b[j]%b[i]==0) b[j]=1001;
      }      
    }
    sort(b, b+m, cmp);
    jump(0);
    cout << best[0] << " " << best[1] <<  endl;
    return 0;
}
         
