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

#include <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;

typedef struct {
    int key;
    int value;
} japp;

long    n, m;
long    gmax   = -1;
long    gmaxi  = -1;

int     jumps[256];
int     app[200001];

queue<japp> q;

int main () {
    scanf ("%ld%ld", &n, &m);
    for (int i = 0; i < m; i ++) scanf ("%d", &jumps[i]);
    for (int i = 0; i <= n; i ++) scanf ("%d", &app[i]);    
    sort(jumps, jumps + m);
    japp tmp;
    tmp.key = 0;
    tmp.value = app[0];
    q.push(tmp);
    for (;;) {
        if (q.empty()) break;
        japp x = q.front();
        q.pop();
        if (gmax < x.value) {
            gmax = x.value;
            gmaxi = x.key;
        }
        for (int j = 0; j < m; j ++) {
            if (x.key + jumps[j] > n) break;
            japp y = x;
            y.value += app[x.key + jumps[j]];
            y.key += jumps[j];
            q.push(y);
        }
    }
    printf ("%ld %ld\n", gmax, gmaxi);
    return 0;
}
