#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n; cin>>n;
vector<int>w(n),v(n);
for(int i=0;i<n;i++)cin>>w[i];
for(int i=0;i<n;i++)cin>>v[i];
int cap; cin>>cap;
vector<vector<int>>dp(n+1,vector<int>(cap+1));
for(int i=1;i<=n;i++)
for(int j=1;j<=cap;j++)
dp[i][j]=w[i-1]<=j?max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]):dp[i-1][j];
int h=dp[n][cap];
cout<<h/10<<" "<<h%10;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpewogICAgaW50IG47IGNpbj4+bjsKICAgIHZlY3RvcjxpbnQ+dyhuKSx2KG4pOwogICAgZm9yKGludCBpPTA7aTxuO2krKyljaW4+PndbaV07CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKWNpbj4+dltpXTsKICAgIGludCBjYXA7IGNpbj4+Y2FwOwogICAgdmVjdG9yPHZlY3RvcjxpbnQ+PmRwKG4rMSx2ZWN0b3I8aW50PihjYXArMSkpOwogICAgZm9yKGludCBpPTE7aTw9bjtpKyspCiAgICAgICAgZm9yKGludCBqPTE7ajw9Y2FwO2orKykKICAgICAgICAgICAgZHBbaV1bal09d1tpLTFdPD1qP21heCh2W2ktMV0rZHBbaS0xXVtqLXdbaS0xXV0sZHBbaS0xXVtqXSk6ZHBbaS0xXVtqXTsKICAgIGludCBoPWRwW25dW2NhcF07CiAgICBjb3V0PDxoLzEwPDwiICI8PGglMTA7Cn0K