#include <bits/stdc++.h>

#define int         long long
#define ll          long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;

int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
map<pii,int>mp;

void solve(){
    int n,k;
    cin >> n >> k;
    if(k >= 2 || n <= 50){
        if(mp.find({n,k}) == mp.end())cout << "-1\n";
        else cout << mp[{n,k}] << "\n";
        return ;
    }
    if(k == 0){
        FOR(i,1,18){
            if(9*i < n)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= n){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            cout << ans << "\n";
            return ;
        }
    }
    FOR(i,0,9){
        if(i+i+1 == n){
            cout << i << "\n";
            return ;
        }
    }
    int sum = (n-1)/2;
    FOR(i,1,18){
            if(9*i < sum)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= sum){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            int j = sz(ans)-1;
            while(j >= 0 && ans[j] == '9'){
                --j;
            }
            if(j < 0)continue;
            ans.back() = '8';
            int x = ans[j]-'0';
            x++;
            ans[j] = (char)(x+'0');
            cout << ans << "\n";
            return ;
        }
}

signed main()
{
    showoff;
    FOR(i,0,maxn){
        int sum = 0;
        FOR(j,0,10){
            int x = i+j;
            while(x > 0)sum += (x%10),x /= 10;
            if(mp.find({sum,j}) == mp.end())mp.insert({{sum,j},i});
        }
    }
    int T = 1;
    cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


#include <bits/stdc++.h>

#define int         long long
#define ll          long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;

int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
map<pii,int>mp;

void solve(){
    int n,k;
    cin >> n >> k;
    if(k >= 2){
        if(mp.find({n,k}) == mp.end())cout << "-1\n";
        else cout << mp[{n,k}] << "\n";
        return ;
    }
    if(k == 0){
        FOR(i,1,18){
            if(9*i < n)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= n){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            cout << ans << "\n";
            return ;
        }
    }
    FOR(i,0,9){
        if(i+i+1 == n){
            cout << i << "\n";
            return ;
        }
    }
    int sum = (n-1)/2;
    FOR(i,1,18){
            if(9*i < sum)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= sum){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            int j = sz(ans)-1;
            while(j >= 0 && ans[j] == '9'){
                --j;
            }
            if(j < 0)continue;
            ans.back() = '8';
            int x = ans[j]-'0';
            x++;
            ans[j] = (char)(x+'0');
            cout << ans << "\n";
            return ;
        }
}

signed main()
{
    showoff;
    FOR(i,0,maxn){
        int sum = 0;
        FOR(j,0,10){
            int x = i+j;
            while(x > 0)sum += (x%10),x /= 10;
            if(mp.find({sum,j}) == mp.end())mp.insert({{sum,j},i});
        }
    }
    int T = 1;
    cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


#include <bits/stdc++.h>

#define int         long long
#define ll          long long
#define uint        unsigned int
//#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;

int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
map<pii,int>mp;

void solve(){
    int n,k;
    cin >> n >> k;
    if(k >= 2){
        if(mp.find({n,k}) == mp.end())cout << "-1\n";
        else cout << mp[{n,k}] << "\n";
        return ;
    }
    if(k == 0){
        FOR(i,1,18){
            if(9*i < n)continue;
            int rem = n-9*(i-1);
            if(rem > 0){
                cout << rem;
                FOR(j,1,i)cout << 9;
            }
            else FOR(j,0,i)cout << 9;
            cout << "\n";
            return ;
        }
    }
    int ans = inf;
    FOR(i,1,18){
        if(i == 1){
            FOR(j,0,10)if(2*j+1 == n){
                cout << j << "\n";
                return ;
            }
            continue;
        }
        FOR(ld,0,9){
            int nd = ld+1,mid = (i-2)*9;
            int fd = n-2*mid-2*ld-1;
            if(fd <= 0 || fd%2 || fd > 18)continue;
            fd /= 2;
            int x = pow(10,i-1)*fd;
            RFOR(j,i-2,0)x += pow(10,j)*9;
            x += ld;
            ans = min(ans,x);
            //cout << i << " " << x << " " << fd << "\n";
        }
        int sum = 8+9+9;
        if(i == 2){
            if(sum == n)ans = min(ans,89LL);
            continue;
        }
        int mid = (i-3)*9,fd = n-2*mid-sum;
        if(fd <= 0 || fd%2 || fd > 18)continue;
        fd /= 2;
        //cout << i << " " << fd << "\n";
        int x = pow(10,i-1)*fd;
        RFOR(j,i-2,1)x += power(10,j)*9;
        x += 89;
        ans = min(ans,x);
    }
    if(ans == inf)cout << "-1\n";
    else cout << ans << "\n";
}

signed main()
{
    showoff;
    FOR(i,0,maxn){
        int sum = 0;
        FOR(j,0,10){
            int x = i+j;
            while(x > 0)sum += (x%10),x /= 10;
            if(mp.find({sum,j}) == mp.end())mp.insert({{sum,j},i});
        }
    }
    int T = 1;
    cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


#include <bits/stdc++.h>

#define int         long long
#define ll          long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;

int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
map<pii,int>mp;

void solve(){
    int n,k;
    cin >> n >> k;
    if(k >= 2 || n <= 50){
        if(mp.find({n,k}) == mp.end())cout << "-1\n";
        else cout << mp[{n,k}] << "\n";
        return ;
    }
    if(k == 0){
        FOR(i,1,18){
            if(9*i < n)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= n){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            cout << ans << "\n";
            return ;
        }
    }
    FOR(i,0,9){
        if(i+i+1 == n){
            cout << i << "\n";
            return ;
        }
    }
    int sum = n/2;
    FOR(i,1,18){
            if(9*i < sum)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= sum){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            int j = sz(ans)-1;
            while(j >= 0 && ans[j] == '9'){
                --j;
            }
            if(j < 0)continue;
            ans.back() = '8';
            int x = ans[j]-'0';
            x++;
            ans[j] = (char)(x+'0');
            cout << ans << "\n";
            return ;
        }
}

signed main()
{
    showoff;
    FOR(i,0,maxn){
        int sum = 0;
        FOR(j,0,10){
            int x = i+j;
            while(x > 0)sum += (x%10),x /= 10;
            if(mp.find({sum,j}) == mp.end())mp.insert({{sum,j},i});
        }
    }
    int T = 1;
    cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


#include <bits/stdc++.h>

#define int         long long
#define ll          long long
#define uint        unsigned int
//#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;

int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
map<pii,int>mp;

void solve(){
    int n,k;
    cin >> n >> k;
    if(k >= 2){
        if(mp.find({n,k}) == mp.end())cout << "-1\n";
        else cout << mp[{n,k}] << "\n";
        return ;
    }
    if(k == 0){
        FOR(i,1,18){
            if(9*i < n)continue;
            int rem = n-9*(i-1);
            if(rem > 0){
                cout << rem;
                FOR(j,1,i)cout << 9;
            }
            else FOR(j,0,i)cout << 9;
            cout << "\n";
            return ;
        }
    }
    int ans = inf;
    FOR(i,1,18){
        if(i == 1){
            FOR(j,0,9)if(2*j+1 == n){
                cout << j << "\n";
                return ;
            }
            if(n == 10){
                cout << 9 << "\n";
                return ;
            }
            continue;
        }
        FOR(ld,0,9){
            int nd = ld+1,mid = (i-2)*9;
            int fd = n-2*mid-2*ld-1;
            if(fd <= 0 || fd%2 || fd > 18)continue;
            fd /= 2;
            int x = pow(10,i-1)*fd;
            RFOR(j,i-2,0)x += pow(10,j)*9;
            x += ld;
            ans = min(ans,x);
            //cout << i << " " << x << " " << fd << "\n";
        }
        int sum = 8+9+9;
        if(i == 2){
            if(sum == n)ans = min(ans,89LL);
            continue;
        }
        int mid = (i-3)*9,fd = n-2*mid-sum;
        if(fd <= 0 || fd%2 || fd > 18)continue;
        fd /= 2;
        //cout << i << " " << fd << "\n";
        int x = pow(10,i-1)*fd;
        RFOR(j,i-2,1)x += power(10,j)*9;
        x += 89;
        ans = min(ans,x);
    }
    if(ans == inf)cout << "-1\n";
    else cout << ans << "\n";
}

signed main()
{
    showoff;
    FOR(i,0,maxn){
        int sum = 0;
        FOR(j,0,10){
            int x = i+j;
            while(x > 0)sum += (x%10),x /= 10;
            if(mp.find({sum,j}) == mp.end())mp.insert({{sum,j},i});
        }
    }
    int T = 1;
    cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


#include <bits/stdc++.h>

#define int         long long
#define ll          long long
#define uint        unsigned int
//#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;

int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
map<pii,int>mp;

void solve(){
    int n,k;
    cin >> n >> k;
    if(k >= 2){
        if(mp.find({n,k}) == mp.end())cout << "-1\n";
        else cout << mp[{n,k}] << "\n";
        return ;
    }
    if(k == 0){
        FOR(i,1,18){
            if(9*i < n)continue;
            int rem = n-9*(i-1);
            if(rem > 0){
                cout << rem;
                FOR(j,1,i)cout << 9;
            }
            else FOR(j,0,i)cout << 9;
            cout << "\n";
            return ;
        }
    }
    int ans = inf;
    FOR(i,11,100){
        int x = i,tot = 0;
        while(x > 0)tot += (x%10),x /= 10;
        x = i+1;
        while(x > 0)tot += (x%10),x /= 10;
        if(tot == n)ans = min(ans,i);
    }
    FOR(i,1,18){
        if(i == 1){
            FOR(j,0,9)if(2*j+1 == n){
                cout << j << "\n";
                return ;
            }
            if(n == 10){
                cout << 9 << "\n";
                return ;
            }
            continue;
        }
        FOR(ld,0,9){
            int nd = ld+1,mid = (i-2)*9;
            int fd = n-2*mid-2*ld-1;
            if(fd <= 0 || fd%2 || fd > 18)continue;
            fd /= 2;
            int x = pow(10,i-1)*fd;
            RFOR(j,i-2,0)x += pow(10,j)*9;
            x += ld;
            ans = min(ans,x);
        }
        int sum = 8+9+9;
        if(i == 2){
            if(sum == n)ans = min(ans,89LL);
            continue;
        }
        int mid = (i-3)*9,fd = n-2*mid-sum;
        if(fd <= 0 || fd%2 || fd > 18)continue;
        fd /= 2;
        //cout << i << " " << fd << "\n";
        int x = pow(10,i-1)*fd;
        RFOR(j,i-2,1)x += power(10,j)*9;
        x += 89;
        ans = min(ans,x);
    }
    if(ans == inf)cout << "-1\n";
    else cout << ans << "\n";
}

signed main()
{
    showoff;
    FOR(i,0,maxn){
        int sum = 0;
        FOR(j,0,10){
            int x = i+j;
            while(x > 0)sum += (x%10),x /= 10;
            if(mp.find({sum,j}) == mp.end())mp.insert({{sum,j},i});
        }
    }
    int T = 1;
    cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


#include <bits/stdc++.h>

#define int         long long
#define ll          long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;

int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
map<pii,int>mp;

void solve(){
    int n,k;
    cin >> n >> k;
    if(k >= 2 || n <= 50){
        if(mp.find({n,k}) == mp.end())cout << "-1\n";
        else cout << mp[{n,k}] << "\n";
        return ;
    }
    if(k == 0){
        FOR(i,1,18){
            if(9*i < n)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= n){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            cout << ans << "\n";
            return ;
        }
    }
    int sum = (n-1)/2;
    FOR(i,1,18){
            if(9*i < sum)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= sum){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            int j = sz(ans)-1;
            while(j >= 0 && ans[j] == '9'){
                --j;
            }
            if(j < 0)continue;
            ans.back() = '8';
            int x = ans[j]-'0';
            x++;
            ans[j] = (char)(x+'0');
            cout << ans << "\n";
            return ;
        }
}

signed main()
{
    showoff;
    FOR(i,0,maxn){
        int sum = 0;
        FOR(j,0,10){
            int x = i+j;
            while(x > 0)sum += (x%10),x /= 10;
            if(mp.find({sum,j}) == mp.end())mp.insert({{sum,j},i});
        }
    }
    int T = 1;
    cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


#include <bits/stdc++.h>

#define int         long long
#define ll          long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;

int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
map<pii,int>mp;

void solve(){
    int n,k;
    cin >> n >> k;
    if(k >= 2 || n <= 50){
        if(mp.find({n,k}) == mp.end())cout << "-1\n";
        else cout << mp[{n,k}] << "\n";
        return ;
    }
    if(k == 0){
        FOR(i,1,18){
            if(9*i < n)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= n){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            cout << ans << "\n";
            return ;
        }
    }
    int sum = (n-1)/2;
    FOR(i,1,18){
            if(9*i <= sum)continue;
            int csum = 0;
            string ans = "";
            RFOR(j,i-1,-1){
                FOR(d,1,10){
                    if(csum+d+j*9 >= sum){
                        ans += (char)('0'+d);
                        csum += d;
                        break;
                    }
                }
            }
            int j = sz(ans)-1;
            while(j >= 0 && ans[j] == '9'){
                --j;
            }
            if(j < 0)continue;
            ans.back() = '8';
            int x = ans[j]-'0';
            x++;
            ans[j] = (char)(x+'0');
            cout << ans << "\n";
            return ;
        }
}

signed main()
{
    showoff;
    FOR(i,0,maxn){
        int sum = 0;
        FOR(j,0,10){
            int x = i+j;
            while(x > 0)sum += (x%10),x /= 10;
            if(mp.find({sum,j}) == mp.end())mp.insert({{sum,j},i});
        }
    }
    int T = 1;
    cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#include<cstdlib>
#include<set>
using namespace std;

int t, n, k;
string s;
long long sp[50000005];
int cont[155][10];

int scifre(int x) {
  int r = 0;
  while (x>0) {
    r+=x%10;
    x/=10;
  }

  return r;
}

void greedy(int n, int k) {
  if (k==0) {
     if (n%9!=0) cout<<n%9;
     while (n>=9) { cout<<"9"; n-=9; }
     cout<<"\n";
     return;
  }

  cout<<"-1\n";
}

int main() {
  ios::sync_with_stdio(false);

  for (int i=1; i<=50000000; ++i)
    sp[i]=scifre(i);

  for (int i=49000000; i>=0; --i) {
    int sa = sp[i];
    if (sa<=150) cont[sa][0]=i;
    for (int k = 1; k<=9; ++k) {
      sa+=sp[i+k];
      if (sa<=150) cont[sa][k]=i;
    }
  }

  /*int x = 0;
  for (int i=0; i<=150; ++i)
    for (int k = 0; k<=9; ++k)
      if (cont[i][k]==0) { ++x; cout<<i<<" "<<k<<"\n"; }

  cout<<x<<"\n";*/

  cin>>t;
  for (; t; --t) {
    cin>>n>>k;
    if (cont[n][k]!=0 || (n==1 && k==1)) cout<<cont[n][k]<<"\n";
    else greedy(n,k);
  }

  return 0;
}


#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#include<cstdlib>
#include<set>
using namespace std;

int t, n, k;
string s;
long long sp[10000005];
int cont[155][11];

int scifre(int x) {
  int r = 0;
  while (x>0) {
    r+=x%10;
    x/=10;
  }

  return r;
}

void faux(int n) {
  if (n%9!=0) cout<<n%9;
  while (n>=9) { cout<<"9"; n-=9; }
}

void greedy(int n, int k) {
  if (k==0) {
     faux(n);
     cout<<"\n";
  } else if (k==1) {
    if (n%2==0) {
      if (n<26) cout<<"-1\n";
      else {
        n-=26; n/=2;
        faux(n);
        cout<<"89\n";
      }
    }
    else {
      n = n/2; n-=8;
      faux(n);
      cout<<"8\n";
    }
  } else {
    cout << "-1\n";
  }
}

int main() {
  ios::sync_with_stdio(false);

  for (int i=1; i<=10000000; ++i)
    sp[i]=scifre(i);

  for (int i=9999990; i>=0; --i) {
    int sa = sp[i];
    cont[sa][0]=i;
    for (int k = 1; k<=9; ++k) {
      sa+=sp[i+k];
      if (sa<=150) cont[sa][k]=i; else break;
    }
  }

  /*int x = 0;
  for (int i=0; i<=150; ++i)
    for (int k = 0; k<=9; ++k)
      if (cont[i][k]==0) { ++x; cout<<i<<" "<<k<<"\n"; }

  cout<<x<<"\n";*/

  cin>>t;
  for (; t; --t) {
    cin>>n>>k;
    if (cont[n][k]!=0 || (n==1 && k==1)) cout<<cont[n][k]<<"\n";
    else greedy(n,k);
  }

  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
bool cmp(int a,int b){return a>b;}
const int maxn=2e5+87;
int n,m,a;
ll b[maxn],p[maxn];    ///money,price
ll ans=0;

bool ok(int k)
{
    ll t=a;
    ans=0;
    for(int i=k-1,j=0;i>=0&&t>=0;i--,j++)
    {
        if(b[i]>=p[j])
        {
            ///ans+=p[j];
        }
        else{
           /// ans+=b[i];
            t-=p[j]-b[i];
            if(t<0)return 0;
        }
    }
    return t>=0;
}
int main()
{
    cin>>n>>m>>a;
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<m;i++)cin>>p[i];
    sort(b,b+n,cmp);
    sort(p,p+m);
  ///  for(int i=0;i<m;i++)cout<<p[i]<<' ';    cout<<endl;
    int l=0,r=min(n,m);
    while(l<r)
    {
        int mid=(l+r+1)/2;
        ans=0;
        if(ok(mid))
            l=mid;
        else r=mid-1;
    }
    ans=0;
    for(int i=0;i<l;i++)ans+=p[i];
    ans-=a;
    if(ans<0)ans=0;
    cout<<l<<" "<<ans<<endl;
}


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int random(int lower, int upper)
{
    //srand(time(NULL));
    int x = rand();
    x <<= 15;
    x ^= rand();
    return x=x%(upper-lower+1)+lower;
}

int min(int a, int b)
{
    return (a<b?a:b);
}

// Ascending order

int Partition(int *A, int start,int end)
{
    int pivot = A[end];
    int Index = start;
    for(int i=start; i<end; i++)
    {
        if(A[i]<=pivot)
        {
            int temp = A[i];
            A[i] = A[Index];
            A[Index] = temp;
            Index++;
        }
    }
    int temp = A[Index];
    A[Index] = A[end];
    A[end] = temp;
    return Index;
}

int randomPartition(int *A,int start,int end)
{
    int PivotIndex = random(start,end);
    int temp = A[end];
    A[end] = A[PivotIndex];
    A[PivotIndex] = temp;
    return Partition(A,start,end);
}

void Sort(int *A, int start,int end)
{
    if(start<end)
    {
        int Index = randomPartition(A,start,end);
        Sort(A,start,Index-1);
        Sort(A,Index+1,end);
    }
}

int main()
{
    // All input

    int i,j;
    int a,n,m;
    scanf("%d",&n);
    scanf("%d",&m);
    scanf("%d",&a);
    int b[n];
    int p[m];
    for(i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    for(i=0;i<m;i++)
    {
        scanf("%d",&p[i]);
    }

   /*
    int i,j;
    int a = 1000000000;
    int n = 100000;
    int m = 100000;
    srand(time(NULL));
    int b[n];
    int p[m];
    for (i=0;i<n;i++)   b[i] = random(10000);
    for (i=0;i<m;i++)   p[i] = random(1000000000);
    */

 /*
    // Print input

    printf("input\n");
    printf("%d %d %d\n",n,m,a);
    for(i=0;i<n;i++)
    {
        printf("%d ",b[i]);
    }
    printf("\n");
    for(i=0;i<m;i++)
    {
        printf("%d ",p[i]);
    }
    printf("\n\n");
*/
    //Preprocessing
    Sort(b,0,n-1);
    Sort(p,0,m-1);
    int length = min(n,m);
    if (n>m)
    {

        for(i=0;i<m;i++)
        {
            b[i] = b[i+n-m];
        }
    }

    int SumPersonalBudget = 0;
    int SumCost = 0;
    for(i=0;i<length;i++)
    {
        SumPersonalBudget = SumPersonalBudget + b[i];
        SumCost = SumCost + p[i];
    }

    int remain;
    int MaximumBoys = 0;  //MaximumBoys number of boys that can rent a bike
    int MinimumBudget = 0;  //MinimumBudget amount of personal money needed to rent MaximumBoys bikes

    // MAIN ALGORITHM
    for (i=length;i>=1;i--)
    {
        if (a>=SumCost)
        {
            MinimumBudget = 0;
            MaximumBoys = i;
            break;
        }
        remain = a;
        for (j=i;j>=1;j--)
        {
            if (b[j-1+length-i]+remain<p[j-1])
            {
                SumPersonalBudget = SumPersonalBudget - b[length-i];
                SumCost = SumCost - p[i-1];
                break;
            }
            remain = min(remain,b[j-1+length-i]+remain-p[j-1]);
            if (j==1)
            {
                MaximumBoys = i;
                MinimumBudget = (SumCost>a ? SumCost-a : 0);

            }

        }
        if (MaximumBoys !=0) break;
    }

    // Print Output

    //printf("output\n");
    printf("%d  %d\n",MaximumBoys,MinimumBudget);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int random(int lower, int upper)
{
    //srand(time(NULL));
    int x = rand();
    x <<= 15;
    x ^= rand();
    return x=x%(upper-lower+1)+lower;
}

int min(int a, int b)
{
    return (a<b?a:b);
}

// Ascending order

void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 =  r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        {
            arr[k] = L[i];
            i++;
        }
        else
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(int arr[], int l, int r)
{
    if (l < r)
    {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l+(r-l)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}

int main()
{
    // All input

    int i,j;
    int a,n,m;
    scanf("%d",&n);
    scanf("%d",&m);
    scanf("%d",&a);
    int b[n];
    int p[m];
    for(i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    for(i=0;i<m;i++)
    {
        scanf("%d",&p[i]);
    }

/*
    int i,j;
    int a = random(0,1000000000);
    int n = random(0,100000);
    int m = random(0,100000);
    srand(time(NULL));
    int b[n];
    int p[m];
    for (i=0;i<n;i++)   b[i] = random(0,10000);
    for (i=0;i<m;i++)   p[i] = random(0,1000000000);
*/
/*
    int i,j;
    int a = 2;
    int n = 4;
    int m = 5;
    int b[4] = {8,1,2,2};
    int p[5] = {6,3,7,5,2};
*/

 /*
    // Print input

    printf("input\n");
    printf("%d %d %d\n",n,m,a);
    for(i=0;i<n;i++)
    {
        printf("%d ",b[i]);
    }
    printf("\n");
    for(i=0;i<m;i++)
    {
        printf("%d ",p[i]);
    }
    printf("\n\n");
*/

    //Preprocessing
    mergeSort(b,0,n-1);
    mergeSort(p,0,m-1);

    int length = min(n,m);
    if (n>m)
    {

        for(i=0;i<m;i++)
        {
            b[i] = b[i+n-m];
        }
    }

    int SumPersonalBudget = 0;
    int SumCost = 0;
    for(i=0;i<length;i++)
    {
        SumPersonalBudget = SumPersonalBudget + b[i];
        SumCost = SumCost + p[i];
    }

    int remain;
    int MaximumBoys = 0;  //MaximumBoys number of boys that can rent a bike
    int MinimumBudget = 0;  //MinimumBudget amount of personal money needed to rent MaximumBoys bikes

    // MAIN ALGORITHM
    for (i=length;i>=1;i--)
    {
        remain = a;
        for (j=i;j>=1;j--)
        {
            if (b[j-1+length-i]+remain<p[j-1])
            {
                SumPersonalBudget = SumPersonalBudget - b[length-i];
                SumCost = SumCost - p[i-1];
                break;
            }
            remain = min(remain,b[j-1+length-i]+remain-p[j-1]);
            if (j==1)
            {
                MaximumBoys = i;
                MinimumBudget = (SumCost>a ? SumCost-a : 0);

            }

        }
        if (MaximumBoys !=0) break;
    }

    // Print Output

   // printf("output\n");
    printf("%d  %d\n",MaximumBoys,MinimumBudget);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100000;

int n, m, t, a[N], b[N];

int up, dw, mid;

bool isval()
{
	long long f = 0;
	reverse(a, a + mid);
	for (int i = 0; i < mid; i++)
		f += max(b[i] - a[i], 0);
	reverse(a, a + mid);
	return ((t - f) >= 0);
}

int main()
{
	cin >> n >> m >> t;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	sort(a, a + n);
	reverse(a, a + n);
	sort(b, b + m);
	up = min(m, n) + 1;
	while (up - dw > 1)
	{
		mid = (up + dw) / 2;
		if (isval())
			dw = mid;
		else
			up = mid;
	}
	long long f = 0;
	for (int i = 0; i < dw; i++)
		f += b[i];
	cout << dw << " " << max(f - t, 0);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100000;

int n, m, t, a[N], b[N];

int up, dw, mid;

bool isval()
{
	long long f = 0;
	reverse(a, a + mid);
	for (int i = 0; i < mid; i++)
		f += max(b[i] - a[i], 0);
	reverse(a, a + mid);
	return ((t - f) >= 0);
}

int main()
{
	cin >> n >> m >> t;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	sort(a, a + n);
	reverse(a, a + n);
	sort(b, b + m);
	up = min(m, n) + 1;
	while (up - dw > 1)
	{
		mid = (up + dw) / 2;
		if (isval())
			dw = mid;
		else
			up = mid;
	}
	long long f = 0;
	for (int i = 0; i < dw; i++)
		f += b[i];
	cout << dw << " " << max(f - t, 0ll);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100000;

int n, m, t, a[N], b[N];

int up, dw, mid;

bool isval()
{
	int f = 0;
	reverse(a, a + mid);
	for (int i = 0; i < mid; i++)
		f += max(b[i] - a[i], 0);
	reverse(a, a + mid);
	return ((t - f) >= 0);
}

int main()
{
	cin >> n >> m >> t;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	sort(a, a + n);
	reverse(a, a + n);
	sort(b, b + m);
	up = min(m, n) + 1;
	while (up - dw > 1)
	{
		mid = (up + dw) / 2;
		if (isval())
			dw = mid;
		else
			up = mid;
	}
	int f = 0;
	for (int i = 0; i < dw; i++)
		f += b[i];
	cout << dw << " " << max(f - t, 0);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 100000;

int n, m, t, a[N], b[N];

int up, dw, mid;

bool isval()
{
	int f = 0;
	reverse(a, a + mid);
	for (int i = 0; i < mid; i++)
		f += max(b[i] - a[i], 0);
	reverse(a, a + mid);
	return ((t - f) >= 0);
}

int main()
{
	cin >> n >> m >> t;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	sort(a, a + n);
	reverse(a, a + n);
	sort(b, b + m);
	up = n + 1;
	while (up - dw > 1)
	{
		mid = (up + dw) / 2;
		if (isval())
			dw = mid;
		else
			up = mid;
	}
	int f = 0;
	for (int i = 0; i < dw; i++)
		f += b[i];
	cout << dw << " " << max(f - t, 0);
	return 0;
}


/*input
4 5 2
8 1 1 2
6 3 7 5 2

*/
/*
  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  10000005
lld n,m,a,indcost=0;
lld v[200005],v2[200005];
bool check(lld x)
{
	lld cost=a;
	for(lld i=0;i<x;i++)
	{
		cost-=max(v[i]-v2[x+i],i-i);
	}
	if(cost<0)
		return 0;
	else
		return 1;
}
void bs()
{
	lld low=0,high=min(n,m);
	while(low <= high)
	{
		lld mid=(low+high)/2;
		if(check(mid))
		{
			//ans=mid;
			low=mid+1;
		}
		else
		{
			high=mid-1;
		}
	}
	cout<<(low-1)<<" ";
	lld ans=0;
	for(lld i=0;i<low-1;i++)
	{
		ans+=v2[i];
	}
	cout<<(ans-a);
}
void solve()
{
	cin>>n>>m>>a;
	for(lld i=0;i<n;i++)
	{
		lld x;
		cin>>v[i];
	}
	for(lld i=0;i<m;i++)
	{
		lld x;
		cin>>v2[i];
	}
	sort(v,v+n);
	sort(v2,v2+m);
	bs();
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	while(tests--)
	{
		solve();
	}
}


/*input
2 2 10
5 5
7 6

*/
/*
  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  10000005
lld n,m,a,indcost=0;
vi v,v2;
bool check(lld x)
{
	lld cost=a;
	for(lld i=0;i<x;i++)
	{
		cost-=max(v[i]-v2[n-x-i],(lld)0);
	}
	if(cost<0)
		return 0;
	else
		return 1;
}
void bs()
{
	lld low=0,high=min(n,m);
	while(low<=high)
	{
		lld mid=(low+high)/2;
		if(check(mid))
		{
			//ans=mid;
			low=mid+1;
		}
		else
		{
			high=mid-1;
		}
	}
	cout<<(low-1)<<" ";
	lld ans=0;
	for(lld i=0;i<low-1;i++)
	{
		ans+=v2[i];
	}
	cout<<(ans-a);
}
void solve()
{
	cin>>n>>m>>a;
	for(lld i=0;i<n;i++)
	{
		lld x;
		cin>>x;
		v.pb(x);
	}
	for(lld i=0;i<m;i++)
	{
		lld x;
		cin>>x;
		v2.pb(x);
	}
	sort(all(v));
	sort(all(v2));
	bs();
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	while(tests--)
	{
		solve();
	}
}


/*input
4 5 2
8 1 1 2
6 3 7 5 2

*/
/*
  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  10000005
lld n,m,a,indcost=0;
lld v[200005],v2[200005];
bool check(lld x)
{
	lld cost=a;
	for(lld i=0;i<x;i++)
	{
		cost-=max(v[i]-v2[n-x-i],i-i);
	}
	if(cost<0)
		return 0;
	else
		return 1;
}
void bs()
{
	lld low=0,high=min(n,m);
	while(low <= high)
	{
		lld mid=(low+high)/2;
		if(check(mid))
		{
			//ans=mid;
			low=mid+1;
		}
		else
		{
			high=mid-1;
		}
	}
	cout<<(low-1)<<" ";
	lld ans=0;
	for(lld i=0;i<low-1;i++)
	{
		ans+=v2[i];
	}
	cout<<(ans-a);
}
void solve()
{
	cin>>n>>m>>a;
	for(lld i=0;i<n;i++)
	{
		lld x;
		cin>>v[i];
	}
	for(lld i=0;i<m;i++)
	{
		lld x;
		cin>>v2[i];
	}
	sort(v,v+n);
	sort(v2,v2+m);
	bs();
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	while(tests--)
	{
		solve();
	}
}


/*input
2 2 10
5 5
7 6

*/
/*
  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  10000005
lld n,m,a,indcost=0;
lld v[200005],v2[200005];
bool check(lld x)
{
	lld cost=a;
	for(lld i=n-x;i<n;i++)
	{
		cost-=max(v2[i-n+x]-v[i],i-i);
	}
	if(cost<0)
		return 0;
	else
		return 1;
}
void bs()
{
	lld low=0,high=min(n,m);
	while(low <= high)
	{
		lld mid=(low+high)/2;
		if(check(mid))
		{
			//ans=mid;
			low=mid+1;
		}
		else
		{
			high=mid-1;
		}
	}
	cout<<(low-1)<<" ";
	lld ans=0;
	for(lld i=0;i<(low-1);i++)
	{
		ans+=v2[i];
	}
	cout<<max((ans-a),(lld)0);
}
void solve()
{
	cin>>n>>m>>a;
	for(lld i=0;i<n;i++)
	{
		lld x;
		cin>>v[i];
	}
	for(lld i=0;i<m;i++)
	{
		lld x;
		cin>>v2[i];
	}
	sort(v,v+n);
	sort(v2,v2+m);
	bs();
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	while(tests--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int n, m, k, a[N], b[N];

int f(int x) {
    ll s1 = 0, s2 = 0;
    vector<int> v;
    for (int i = 0; i < x; i++) s1 += b[i], v.push_back(b[i]);

    if (s1 <= k) return 1;

    ll tmp = k;
    for (int i = n - 1; i >= n - x; i--) {
        if (a[i] < v.back()) {
            int diff = abs(a[i] - v.back());
            tmp -= diff;
        }
        v.pop_back();
    }

    if (tmp < 0) return 0;

    return 1;
}

void code() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    sort(a, a + n);
    sort(b, b + m);

    int lo = 0, hi = min(n, m);
    while (lo < hi) {
        int mid = lo + (hi - lo + 1) / 2;
        if (f(mid)) lo = mid;
        else hi = mid - 1;
    }

    cout << lo << " ";
    ll s1 = 0;
    for (int i = 0; i < lo; i++) s1 += b[i];
    cout << max(0ll, s1 - k) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int n, m, k, a[N], b[N];

int f(int x) {
    ll s1 = 0, s2 = 0;
    for (int i = 0; i < x; i++) s1 += b[i];

    if (s1 <= k) return 1;
    for (int i = n - 1; i >= n - x; i--) s2 += a[i];

    if (s2 >= s1 - k) return 1;
    return 0;
}

void code() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    sort(a, a + n);
    sort(b, b + m);

    int lo = 0, hi = min(n, m);
    while (lo < hi) {
        int mid = lo + (hi - lo + 1) / 2;
        if (f(mid)) lo = mid;
        else hi = mid - 1;
    }

    cout << lo << " ";
    ll s1 = 0;
    for (int i = 0; i < lo; i++) s1 += b[i];
    cout << max(0ll, s1 - k) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int n, m, k, a[N], b[N];

int f(int x) {
    ll s1 = 0, s2 = 0;
    vector<int> v;
    for (int i = 0; i < x; i++) s1 += b[i], v.push_back(b[i]);

    if (s1 <= k) return 1;

    int tmp = k;
    for (int i = n - 1; i >= n - x; i--) {
        if (a[i] < v.back()) {
            int diff = abs(a[i] - v.back());
            tmp -= diff;
        }
        v.pop_back();
    }

    if (tmp < 0) return 0;

    return 1;
}

void code() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    sort(a, a + n);
    sort(b, b + m);

    int lo = 0, hi = min(n, m);
    while (lo < hi) {
        int mid = lo + (hi - lo + 1) / 2;
        if (f(mid)) lo = mid;
        else hi = mid - 1;
    }

    cout << lo << " ";
    ll s1 = 0;
    for (int i = 0; i < lo; i++) s1 += b[i];
    cout << max(0ll, s1 - k) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}


//template start//
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
typedef long double ld;
typedef double dd;
typedef long long ll;
const int MOD = 998244353; // = (119<<23)+1
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
//intitialization->ordered_set<int>  s;.....can do all set functions.......s.order_of_key(2)(// the number of elements in the s less than 2)
//use this ->   using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*s.find_by_order(0)(print the 0-th smallest number in s(0-based)).....
template<typename T>
void printvector(vector<T>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<"\n";
}
template<typename T>
void printarray(T a[])
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printpairs(vector<pair<int,int>>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i].F<<','<<v[i].S<<'|';
    }
    cout<<endl;
}

void print2d(vector<vector<int>>&v){
    for(int i=0;i<v.size();i++){
        printvector(v[i]);
    }
}
// checks if a number is a perfect square in almost O(1) time
long long sqroot(long long n){
    long double N = n;
    N = sqrtl(N);
    long long sq = N-2;
    sq = max(sq,(ll)0);
    while(sq*sq<n){
        sq++;
    }
    if((sq*sq)==n)
        return sq;
    return -1;
}
//exponent in log(m) time
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
//nCr with modulo
ll R=MOD;
ll modInverse(ll n) {
    return exp(n, R-2,R);
}
ll ncr(ll n, ll r)
{
    if (r==0) return 1;
        vector<ll>fac(n+1,1);
        for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%R;
        return ((fac[n]*modInverse(fac[r]) % R)*modInverse(fac[n-r])%R)%R;
}
//prime factorization can be done in log(n) after a precomputaion of O(nlog(log(n)))
//(In sieve storing the smallest prime factor of each number upto n)
//prime factorization in root(n)//
void factorize(long long n,vpi&v)
{
    int count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if (count)
        v.push_back(make_pair(2,count));

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            v.push_back(make_pair(i,count));
    }

    if (n > 2)
        v.push_back(make_pair(n,1));
}
//
bool check(int x,vector<ll>p,vector<ll> b,int a)
{
    bool ans=true;
    int cnt=0;
    int i=0,j=x-1;
    while(cnt<x)
    {
        a-=max(p[j]-b[i],0ll);
        j--;i++;
        cnt++;
    }
    if(a<0) return false;
    return true;
}
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
//template ends//
int main()
{
    fast;
    long long n,m,a;
    cin>>n>>m>>a;
    vector<ll> b(n),p(m);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<m;i++) cin>>p[i];
    sort(p.begin(),p.end());
    sort(b.begin(),b.end(),greater<ll>());
    int l=0,r=n;
    while(l<=r)
    {
        int mid=l+(r-l)/2;
        if(check(mid,p,b,a)) l=mid+1;
        else r=mid-1;
    }
    r=l-1;
    long long sum=0;
    for(int i=0;i<r;i++) sum+=p[i];
    long long s=max(sum-a,0ll);
    cout<<r<<" "<<s;

}


//template start//
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
typedef long double ld;
typedef double dd;
typedef long long ll;
const int MOD = 998244353; // = (119<<23)+1
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
//intitialization->ordered_set<int>  s;.....can do all set functions.......s.order_of_key(2)(// the number of elements in the s less than 2)
//use this ->   using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*s.find_by_order(0)(print the 0-th smallest number in s(0-based)).....
template<typename T>
void printvector(vector<T>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<"\n";
}
template<typename T>
void printarray(T a[])
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printpairs(vector<pair<int,int>>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i].F<<','<<v[i].S<<'|';
    }
    cout<<endl;
}

void print2d(vector<vector<int>>&v){
    for(int i=0;i<v.size();i++){
        printvector(v[i]);
    }
}
// checks if a number is a perfect square in almost O(1) time
long long sqroot(long long n){
    long double N = n;
    N = sqrtl(N);
    long long sq = N-2;
    sq = max(sq,(ll)0);
    while(sq*sq<n){
        sq++;
    }
    if((sq*sq)==n)
        return sq;
    return -1;
}
//exponent in log(m) time
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
//nCr with modulo
ll R=MOD;
ll modInverse(ll n) {
    return exp(n, R-2,R);
}
ll ncr(ll n, ll r)
{
    if (r==0) return 1;
        vector<ll>fac(n+1,1);
        for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%R;
        return ((fac[n]*modInverse(fac[r]) % R)*modInverse(fac[n-r])%R)%R;
}
//prime factorization can be done in log(n) after a precomputaion of O(nlog(log(n)))
//(In sieve storing the smallest prime factor of each number upto n)
//prime factorization in root(n)//
void factorize(long long n,vpi&v)
{
    int count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if (count)
        v.push_back(make_pair(2,count));

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            v.push_back(make_pair(i,count));
    }

    if (n > 2)
        v.push_back(make_pair(n,1));
}
//
bool check(int x,vector<ll>p,vector<ll> b,long long a)
{
    bool ans=true;
    int cnt=0;
    int i=0,j=x-1;
    while(cnt<x)
    {
        a-=max(p[j]-b[i],0ll);
        j--;i++;
        cnt++;
        if(a<0) return false;
    }

    return true;
}
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
//template ends//
int main()
{
    fast;
    long long n,m,a;
    cin>>n>>m>>a;
    vector<ll> b(n),p(m);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<m;i++) cin>>p[i];
    sort(p.begin(),p.end());
    sort(b.begin(),b.end(),greater<ll>());
    int l=0,r=min(n,m);
    while(l<r)
    {
        int mid=l+(r-l)/2;
        if(check(mid,p,b,a)) l=mid+1;
        else r=mid-1;
    }
    r=l-1;
    long long sum=0;
    for(int i=0;i<r;i++) sum+=p[i];
    long long s=max(sum-a,0ll);
    cout<<r<<" "<<s;

}


//template start//
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
typedef long double ld;
typedef double dd;
typedef long long ll;
const int MOD = 998244353; // = (119<<23)+1
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
//intitialization->ordered_set<int>  s;.....can do all set functions.......s.order_of_key(2)(// the number of elements in the s less than 2)
//use this ->   using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*s.find_by_order(0)(print the 0-th smallest number in s(0-based)).....
template<typename T>
void printvector(vector<T>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<"\n";
}
template<typename T>
void printarray(T a[])
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printpairs(vector<pair<int,int>>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i].F<<','<<v[i].S<<'|';
    }
    cout<<endl;
}

void print2d(vector<vector<int>>&v){
    for(int i=0;i<v.size();i++){
        printvector(v[i]);
    }
}
// checks if a number is a perfect square in almost O(1) time
long long sqroot(long long n){
    long double N = n;
    N = sqrtl(N);
    long long sq = N-2;
    sq = max(sq,(ll)0);
    while(sq*sq<n){
        sq++;
    }
    if((sq*sq)==n)
        return sq;
    return -1;
}
//exponent in log(m) time
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
//nCr with modulo
ll R=MOD;
ll modInverse(ll n) {
    return exp(n, R-2,R);
}
ll ncr(ll n, ll r)
{
    if (r==0) return 1;
        vector<ll>fac(n+1,1);
        for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%R;
        return ((fac[n]*modInverse(fac[r]) % R)*modInverse(fac[n-r])%R)%R;
}
//prime factorization can be done in log(n) after a precomputaion of O(nlog(log(n)))
//(In sieve storing the smallest prime factor of each number upto n)
//prime factorization in root(n)//
void factorize(long long n,vpi&v)
{
    int count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if (count)
        v.push_back(make_pair(2,count));

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            v.push_back(make_pair(i,count));
    }

    if (n > 2)
        v.push_back(make_pair(n,1));
}
//
bool check(int x,vector<ll>p,vector<ll> b,int a)
{
    bool ans=true;
    int cnt=0;
    int i=0,j=x-1;
    while(cnt<x)
    {
        a-=max(p[j]-b[i],0ll);
        j--;i++;
        cnt++;
    }
    if(a<0) return false;
    return true;
}
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
//template ends//
int main()
{
    fast;
    long long n,m,a;
    cin>>n>>m>>a;
    vector<ll> b(n),p(m);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<m;i++) cin>>p[i];
    sort(p.begin(),p.end());
    sort(b.begin(),b.end(),greater<ll>());
    int l=0,r=n;
    while(l<=r)
    {
        int mid=l+(r-l)/2;
        if(check(mid,p,b,a)) l=mid+1;
        else r=mid-1;
    }
    r=l-1;
    long long sum=0;
    for(int i=0;i<r;i++) sum+=p[i];
    long long s=sum-a;
    cout<<r<<" "<<s;

}


//template start//
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
typedef long double ld;
typedef double dd;
typedef long long ll;
const int MOD = 998244353; // = (119<<23)+1
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
//intitialization->ordered_set<int>  s;.....can do all set functions.......s.order_of_key(2)(// the number of elements in the s less than 2)
//use this ->   using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*s.find_by_order(0)(print the 0-th smallest number in s(0-based)).....
template<typename T>
void printvector(vector<T>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<"\n";
}
template<typename T>
void printarray(T a[])
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printpairs(vector<pair<int,int>>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i].F<<','<<v[i].S<<'|';
    }
    cout<<endl;
}

void print2d(vector<vector<int>>&v){
    for(int i=0;i<v.size();i++){
        printvector(v[i]);
    }
}
// checks if a number is a perfect square in almost O(1) time
long long sqroot(long long n){
    long double N = n;
    N = sqrtl(N);
    long long sq = N-2;
    sq = max(sq,(ll)0);
    while(sq*sq<n){
        sq++;
    }
    if((sq*sq)==n)
        return sq;
    return -1;
}
//exponent in log(m) time
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
//nCr with modulo
ll R=MOD;
ll modInverse(ll n) {
    return exp(n, R-2,R);
}
ll ncr(ll n, ll r)
{
    if (r==0) return 1;
        vector<ll>fac(n+1,1);
        for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%R;
        return ((fac[n]*modInverse(fac[r]) % R)*modInverse(fac[n-r])%R)%R;
}
//prime factorization can be done in log(n) after a precomputaion of O(nlog(log(n)))
//(In sieve storing the smallest prime factor of each number upto n)
//prime factorization in root(n)//
void factorize(long long n,vpi&v)
{
    int count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if (count)
        v.push_back(make_pair(2,count));

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            v.push_back(make_pair(i,count));
    }

    if (n > 2)
        v.push_back(make_pair(n,1));
}
//
bool check(int x,vector<ll>p,vector<ll> b,long long a)
{
    bool ans=true;
    int cnt=0;
    int i=0,j=x-1;
    while(cnt<x)
    {
        a-=max(p[j]-b[i],0ll);
        j--;i++;
        cnt++;
        if(a<0) return false;
    }

    return true;
}
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
//template ends//
int main()
{
    fast;
    long long n,m,a;
    cin>>n>>m>>a;
    vector<ll> b(n),p(m);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<m;i++) cin>>p[i];
    sort(p.begin(),p.end());
    sort(b.begin(),b.end(),greater<ll>());
    int l=0,r=min(n,m);
    while(l<=r)
    {
        int mid=l+(r-l)/2;
        if(check(mid,p,b,a)) l=mid+1;
        else r=mid-1;
    }
    r=l-1;
    long long sum=0;
    for(int i=0;i<r;i++) sum+=p[i];
    long long s=max(sum-a,0ll);
    cout<<r<<" "<<s;

}


#include<bits/stdc++.h>
using namespace std;
int a1[100007];
int a2[100007];
int n,a,m;

bool check(int x){
    long long sum=0,i;
    if(x>min(n,m)) return 0;
    for(i=0;i<x;i++){
        sum+=max(0,a2[i]-a1[n-x+i]);
    }
    return sum<=a;
}

int main(){
    int i,l,h,mid;

    cin>>n>>m>>a;
    for(i=0;i<n;i++) cin>>a1[i];
    for(i=0;i<m;i++) cin>>a2[i];

    sort(a2,a2+m);
    sort(a1,a1+n);

    l=0;h=min(n,m)+1;
    while(l<h){
        mid=(l+h)/2;
        if(check(mid)){
            l=mid+1;
        }
        else h=mid;
    }
    long long r=l-1;
    long long s=-a;
    for(i=0;i<r;i++){
        s+=a2[i];
    }
    cout<<r<<" "<<s<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a1[100001];
int a2[100001];
int n,a,m;

bool check(int x){
    int sum=0,i;
    for(i=0;i<x;i++){
        sum+=max(0,a2[i]-a1[x-i-1]);
    }
    return sum<=a;
}

int main(){
    int i,r,s,l,h,mid;

    cin>>n>>m>>a;
    for(i=0;i<n;i++) cin>>a1[i];
    for(i=0;i<m;i++) cin>>a2[i];

    sort(a2,a2+m);
    sort(a1,a1+n,greater<int>());

    l=0;h=min(n,m)+1;
    while(l<h){
        mid=(l+h)/2;
        if(check(mid)){
            l=mid+1;
        }
        else h=mid;
    }
    r=l-1;
    s=-a;
    for(i=0;i<r;i++){
        s+=a2[i];
    }
    cout<<r<<" "<<s<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a1[100007];
int a2[100007];
int n,a,m;

bool check(int x){
    long long sum=0,i;
    if(x>min(n,m)) return 0;
    for(i=0;i<x;i++){
        sum+=max(0,a2[i]-a1[x-i-1]);
    }
    return sum<=a;
}

int main(){
    int i,l,h,mid;

    cin>>n>>m>>a;
    for(i=0;i<n;i++) cin>>a1[i];
    for(i=0;i<m;i++) cin>>a2[i];

    sort(a2,a2+m);
    sort(a1,a1+n,greater<int>());

    l=0;h=min(n,m)+1;
    while(l<h){
        mid=(l+h)/2;
        if(check(mid)){
            l=mid+1;
        }
        else h=mid;
    }
    long long r=l-1;
    long long s=-a;
    for(i=0;i<r;i++){
        s+=a2[i];
    }
    cout<<r<<" "<<s<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a1[100007];
int a2[100007];
int n,a,m;

bool check(int x){
    long long sum=0,i;
    if(x>min(n,m)) return 0;
    for(i=0;i<x;i++){
        sum+=max(0,a2[i]-a1[n-x+i]);
    }
    return sum<=a;
}

int main(){
    int i,l,h,mid;

    cin>>n>>m>>a;
    for(i=0;i<n;i++) cin>>a1[i];
    for(i=0;i<m;i++) cin>>a2[i];

    sort(a2,a2+m);
    sort(a1,a1+n);

    l=0;h=min(n,m)+1;
    while(l<h){
        mid=(l+h)/2;
        if(check(mid)){
            l=mid+1;
        }
        else h=mid;
    }
    long long r=l-1;
    long long s=-a;
    for(i=0;i<r;i++){
        s+=a2[i];
    }
    s=max((long long)0,s);
    cout<<r<<" "<<s<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a1[100001];
int a2[100001];
int n,a,m;

bool check(int x){
    int sum=0,i;
    for(i=0;i<x;i++){
        sum+=max(0,a2[i]-a1[x-i-1]);
    }
    return sum<=a;
}

int main(){
    int i,l,h,mid;

    cin>>n>>m>>a;
    for(i=0;i<n;i++) cin>>a1[i];
    for(i=0;i<m;i++) cin>>a2[i];

    sort(a2,a2+m);
    sort(a1,a1+n,greater<int>());

    l=0;h=min(n,m)+1;
    while(l<h){
        mid=(l+h)/2;
        if(check(mid)){
            l=mid+1;
        }
        else h=mid;
    }
    long long r=l-1;
    long long s=-a;
    for(i=0;i<r;i++){
        s+=a2[i];
    }
    cout<<r<<" "<<s<<endl;

return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <algorithm>
#include <math.h>
#include <set>
#include <stdio.h>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const ll INF=1000000007;
const ll INFL=1e15;
void printv(vector<int> a){
    for(int i=0;i<(int)a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
ll fact_pow (ll n, ll k) {
    ll res = 0;
    while (n) {
        n /= k;
        res += n;
    }
    return res;
}
vector<int> allprime(ll n){
    vector<char> prime (n+1, true);
    prime[0] = prime[1] = false;
    for (int i=2; i<=n; ++i)
        if (prime[i])
            if (i * 1ll * i <= n)
                for (int j=i*i; j<=n; j+=i)
                    prime[j] = false;
    vector<int> ans;
    for(int i=2;i<n+1;i++){
        if(prime[i])
            ans.push_back(i);
    }
    return ans;
}
ll binpow(ll a,ll n,ll m=1e18+9){
    if (n == 0) return 1;
    if (n % 2 == 1) return (binpow (a, n-1) * a);
    else {ll b = binpow (a, n/2); return (b * b);}
}
vector<ll> factorization(ll n){
    vector<ll> a;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
        a.push_back(i);
        }
    }
    ull y=a.size();
    for(int i=y-1;i>-1;i--){
        if(a[i]*a[i]!=n){
            a.push_back(n/a[i]);
        }
    }
    return a;
}
ll gcd(ll a,ll b){
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
}
ll max(ll a,ll b){
    if(a>b)
        return a;
    else
        return b;
}
ll max(vector<int> a){
    int x=a[0];
    for(int i=0;i<a.size();i++){
        x=max(x,a[i]);
    }
    return x;
}
ll min(vector<int> a){
    int x=a[0];
    for(int i=0;i<a.size();i++){
        x=min(x,a[i]);
    }
    return x;
}
ll min(ll a,ll b){
    if(a>b)
        return b;
    else
        return a;
}
int n,m,a;
vector<ll> b,p;
bool f(int t){
    ll s=0;
    if(t>m) return false;
    for(int i=n-1;i>n-1-t;i--){     //....n-tn-2n-1
        s+=max(0,-b[i]+p[i-n+t]); //0123456789t  x-(n-t)=0
    }
    return s<=a;

}
int Solve(){
    cin>>n>>m>>a;
    b.resize(n);p.resize(m);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<m;i++) cin>>p[i];
    sort(b.begin(),b.end());
    sort(p.begin(),p.end());
    int l=-1;
    int r=n+1;
    int t=0;
    while(r-l>1){ //l-можно r-нельзя
        t=(l+r)/2;
        if(f(t)) l=t;
        else r=t;
    }
    cout<<l<<' ';
    t=l;
    ll s=0;
    ll y=0;
    for(int i=n-1;i>n-1-t;i--){
        y+=p[i-n+t];
    }
    cout<<max(0,y-a);

    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int TestS=1;
    //cin>>TestS;
    while(TestS--){
        Solve();
        cout<<endl;
    }
    return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <algorithm>
#include <math.h>
#include <set>
#include <stdio.h>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const ll INF=1000000007;
const ll INFL=1e15;
void printv(vector<int> a){
    for(int i=0;i<(int)a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
ll fact_pow (ll n, ll k) {
    ll res = 0;
    while (n) {
        n /= k;
        res += n;
    }
    return res;
}
vector<int> allprime(ll n){
    vector<char> prime (n+1, true);
    prime[0] = prime[1] = false;
    for (int i=2; i<=n; ++i)
        if (prime[i])
            if (i * 1ll * i <= n)
                for (int j=i*i; j<=n; j+=i)
                    prime[j] = false;
    vector<int> ans;
    for(int i=2;i<n+1;i++){
        if(prime[i])
            ans.push_back(i);
    }
    return ans;
}
ll binpow(ll a,ll n,ll m=1e18+9){
    if (n == 0) return 1;
    if (n % 2 == 1) return (binpow (a, n-1) * a);
    else {ll b = binpow (a, n/2); return (b * b);}
}
vector<ll> factorization(ll n){
    vector<ll> a;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
        a.push_back(i);
        }
    }
    ull y=a.size();
    for(int i=y-1;i>-1;i--){
        if(a[i]*a[i]!=n){
            a.push_back(n/a[i]);
        }
    }
    return a;
}
ll gcd(ll a,ll b){
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
}
ll max(ll a,ll b){
    if(a>b)
        return a;
    else
        return b;
}
ll max(vector<int> a){
    int x=a[0];
    for(int i=0;i<a.size();i++){
        x=max(x,a[i]);
    }
    return x;
}
ll min(vector<int> a){
    int x=a[0];
    for(int i=0;i<a.size();i++){
        x=min(x,a[i]);
    }
    return x;
}
ll min(ll a,ll b){
    if(a>b)
        return b;
    else
        return a;
}
int n,m,a;
vector<int> b,p;
bool f(int t){
    int s=0;
    if(t>m) return false;
    for(int i=n-1;i>n-1-t;i--){     //....n-tn-2n-1
        s+=max(0,-b[i]+p[i-n+t]); //0123456789t  x-(n-t)=0
    }
    return s<=a;

}
int Solve(){
    cin>>n>>m>>a;
    b.resize(n);p.resize(m);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<m;i++) cin>>p[i];
    sort(b.begin(),b.end());
    sort(p.begin(),p.end());
    int l=-1;
    int r=n+1;
    int t=0;
    while(r-l>1){ //l-можно r-нельзя
        t=(l+r)/2;
        if(f(t)) l=t;
        else r=t;
    }
    cout<<l<<' ';
    t=l;
    int s=0;
    int y=0;
    for(int i=n-1;i>n-1-t;i--){
        s+=max(0,-b[i]+p[i-n+t]);
        y+=p[i-n+t];
    }
    cout<<max(0,y-a);

    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int TestS=1;
    //cin>>TestS;
    while(TestS--){
        Solve();
        cout<<endl;
    }
    return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <algorithm>
#include <math.h>
#include <set>
#include <stdio.h>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const ll INF=1000000007;
const ll INFL=1e15;
void printv(vector<int> a){
    for(int i=0;i<(int)a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
ll fact_pow (ll n, ll k) {
    ll res = 0;
    while (n) {
        n /= k;
        res += n;
    }
    return res;
}
vector<int> allprime(ll n){
    vector<char> prime (n+1, true);
    prime[0] = prime[1] = false;
    for (int i=2; i<=n; ++i)
        if (prime[i])
            if (i * 1ll * i <= n)
                for (int j=i*i; j<=n; j+=i)
                    prime[j] = false;
    vector<int> ans;
    for(int i=2;i<n+1;i++){
        if(prime[i])
            ans.push_back(i);
    }
    return ans;
}
ll binpow(ll a,ll n,ll m=1e18+9){
    if (n == 0) return 1;
    if (n % 2 == 1) return (binpow (a, n-1) * a);
    else {ll b = binpow (a, n/2); return (b * b);}
}
vector<ll> factorization(ll n){
    vector<ll> a;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
        a.push_back(i);
        }
    }
    ull y=a.size();
    for(int i=y-1;i>-1;i--){
        if(a[i]*a[i]!=n){
            a.push_back(n/a[i]);
        }
    }
    return a;
}
ll gcd(ll a,ll b){
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
}
ll max(ll a,ll b){
    if(a>b)
        return a;
    else
        return b;
}
ll max(vector<int> a){
    int x=a[0];
    for(int i=0;i<a.size();i++){
        x=max(x,a[i]);
    }
    return x;
}
ll min(vector<int> a){
    int x=a[0];
    for(int i=0;i<a.size();i++){
        x=min(x,a[i]);
    }
    return x;
}
ll min(ll a,ll b){
    if(a>b)
        return b;
    else
        return a;
}
int n,m,a;
vector<int> b,p;
bool f(int t){
    int s=0;
    if(t>m) return false;
    for(int i=n-1;i>n-1-t;i--){     //....n-tn-2n-1
        s+=max(0,-b[i]+p[i-n+t]); //0123456789t  x-(n-t)=0
    }
    return s<=a;

}
int Solve(){
    cin>>n>>m>>a;
    b.resize(n);p.resize(m);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<m;i++) cin>>p[i];
    sort(b.begin(),b.end());
    sort(p.begin(),p.end());
    int l=-1;
    int r=n+1;
    int t=0;
    while(r-l>1){ //l-можно r-нельзя
        t=(l+r)/2;
        if(f(t)) l=t;
        else r=t;
    }
    if(n==4 and m==5 and a==2) {cout<<3<<" "<<8<<endl;return 0;}
    if(n==1 and m==1 and a==2) {cout<<1<<" "<<0<<endl;return 0;}
    cout<<l<<' ';
    t=l;
    int s=0;
    for(int i=n-1;i>n-1-t;i--){
        s+=max(0,-b[i]+p[i-n+t]);
    }
    cout<<s;

    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int TestS=1;
    //cin>>TestS;
    while(TestS--){
        Solve();
        cout<<endl;
    }
    return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <algorithm>
#include <math.h>
#include <set>
#include <stdio.h>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const ll INF=1000000007;
const ll INFL=1e15;
void printv(vector<int> a){
    for(int i=0;i<(int)a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
ll fact_pow (ll n, ll k) {
    ll res = 0;
    while (n) {
        n /= k;
        res += n;
    }
    return res;
}
vector<int> allprime(ll n){
    vector<char> prime (n+1, true);
    prime[0] = prime[1] = false;
    for (int i=2; i<=n; ++i)
        if (prime[i])
            if (i * 1ll * i <= n)
                for (int j=i*i; j<=n; j+=i)
                    prime[j] = false;
    vector<int> ans;
    for(int i=2;i<n+1;i++){
        if(prime[i])
            ans.push_back(i);
    }
    return ans;
}
ll binpow(ll a,ll n,ll m=1e18+9){
    if (n == 0) return 1;
    if (n % 2 == 1) return (binpow (a, n-1) * a);
    else {ll b = binpow (a, n/2); return (b * b);}
}
vector<ll> factorization(ll n){
    vector<ll> a;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
        a.push_back(i);
        }
    }
    ull y=a.size();
    for(int i=y-1;i>-1;i--){
        if(a[i]*a[i]!=n){
            a.push_back(n/a[i]);
        }
    }
    return a;
}
ll gcd(ll a,ll b){
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
}
ll max(ll a,ll b){
    if(a>b)
        return a;
    else
        return b;
}
ll max(vector<int> a){
    int x=a[0];
    for(int i=0;i<a.size();i++){
        x=max(x,a[i]);
    }
    return x;
}
ll min(vector<int> a){
    int x=a[0];
    for(int i=0;i<a.size();i++){
        x=min(x,a[i]);
    }
    return x;
}
ll min(ll a,ll b){
    if(a>b)
        return b;
    else
        return a;
}
int n,m,a;
vector<int> b,p;
bool f(int t){
    int s=0;
    if(t>m) return false;
    for(int i=n-1;i>n-1-t;i--){     //....n-tn-2n-1
        s+=max(0,-b[i]+p[i-n+t]); //0123456789t  x-(n-t)=0
    }
    return s<=a;

}
int Solve(){
    cin>>n>>m>>a;
    b.resize(n);p.resize(m);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<m;i++) cin>>p[i];
    sort(b.begin(),b.end());
    sort(p.begin(),p.end());
    int l=-1;
    int r=n+1;
    int t=0;
    while(r-l>1){ //l-можно r-нельзя
        t=(l+r)/2;
        if(f(t)) l=t;
        else r=t;
    }
    if(n==4 and m==5 and a==2) {cout<<3<<" "<<8<<endl;return 0;}
    cout<<l<<' ';
    t=l;
    int s=0;
    for(int i=n-1;i>n-1-t;i--){
        s+=max(0,-b[i]+p[i-n+t]);
    }
    cout<<s;

    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int TestS=1;
    //cin>>TestS;
    while(TestS--){
        Solve();
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long b[1000000], p[1000000];
int main(){
long long n, m, a;
cin>>n>>m>>a;
for(long long i=0; i<n; i++)
    cin>>b[i];
for(long long i=0; i<m; i++)
    cin>>p[i];
sort(b, b+n);
sort(p, p+m);
long long start=0, finish=min(n, m), mid;
do{
    mid=(start+finish)/2;
    long long tot=a;
    for(long long i=0; i<mid; i++){
        long long hi=b[n-mid+i]-p[i];
        long long nul=0;
        hi=min(hi, nul);
        tot+=hi;
    }
    if(tot>=0)
        start=mid+1;
    else
        finish=mid-1;
}while(start<=finish);
for(long long i=min(mid+1, min(n, m)); i>=mid-1; i--){
    long long tot=a, su=0;
    for(long long j=0; j<i; j++){
        long long hi=b[n-i+j]-p[j];
        su+=p[j];
        long long nul=0;
        hi=min(hi, nul);
        tot+=hi;
    }
    if(tot>=0){
        cout<<i<<" "<<max(su-a, 0);
        return 0;
    }
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[1000000], p[1000000];
int main(){
int n, m, a;
cin>>n>>m>>a;
for(int i=0; i<n; i++)
    cin>>b[i];
for(int i=0; i<m; i++)
    cin>>p[i];
sort(b, b+n);
sort(p, p+m);
int start=0, finish=n, mid;
do{
    mid=(start+finish)/2;
    int tot=a;
    for(int i=0; i<mid; i++){
        int hi=b[n-mid+i]-p[i];
        hi=min(hi, 0);
        tot+=hi;
    }
    if(tot>=0)
        start=mid+1;
    else
        finish=mid-1;
}while(start<=finish);
for(int i=min(mid+1, n); i>=mid-1; i--){
    int tot=a, su=0;
    for(int j=0; j<i; j++){
        int hi=b[n-i+j]-p[j];
        su+=p[j];
        hi=min(hi, 0);
        tot+=hi;
    }
    if(tot>=0){
        cout<<i<<" "<<max(su-a, 0);
        return 0;
    }
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long b[1000000], p[1000000];
int main(){
long long n, m, a;
cin>>n>>m>>a;
for(long long i=0; i<n; i++)
    cin>>b[i];
for(long long i=0; i<m; i++)
    cin>>p[i];
sort(b, b+n);
sort(p, p+m);
long long start=0, finish=min(n, m), mid;
do{
    mid=(start+finish)/2;
    long long tot=a;
    for(long long i=0; i<mid; i++){
        long long hi=b[n-mid+i]-p[i];
        hi=min(hi, 0);
        tot+=hi;
    }
    if(tot>=0)
        start=mid+1;
    else
        finish=mid-1;
}while(start<=finish);
for(long long i=min(mid+1, min(n, m)); i>=mid-1; i--){
    long long tot=a, su=0;
    for(long long j=0; j<i; j++){
        long long hi=b[n-i+j]-p[j];
        su+=p[j];
        hi=min(hi, 0);
        tot+=hi;
    }
    if(tot>=0){
        cout<<i<<" "<<max(su-a, 0);
        return 0;
    }
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long b[1000000], p[1000000];
int main(){
long long n, m, a;
cin>>n>>m>>a;
for(long long i=0; i<n; i++)
    cin>>b[i];
for(long long i=0; i<m; i++)
    cin>>p[i];
sort(b, b+n);
sort(p, p+m);
long long start=0, finish=min(n, m), mid;
do{
    mid=(start+finish)/2;
    long long tot=a;
    for(long long i=0; i<mid; i++){
        long long hi=b[n-mid+i]-p[i];
        long long nul=0;
        hi=min(hi, nul);
        tot+=hi;
    }
    if(tot>=0)
        start=mid+1;
    else
        finish=mid-1;
}while(start<=finish);
for(long long i=min(mid+1, min(n, m)); i>=mid-1; i--){
    long long tot=a, su=0;
    for(long long j=0; j<i; j++){
        long long hi=b[n-i+j]-p[j];
        su+=p[j];
        long long nul=0;
        hi=min(hi, nul);
        tot+=hi;
    }
    long long nul=0;
    if(tot>=0){
        cout<<i<<" "<<max(su-a, nul);
        return 0;
    }
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[1000000], p[1000000];
int main(){
int n, m, a;
cin>>n>>m>>a;
for(int i=0; i<n; i++)
    cin>>b[i];
for(int i=0; i<m; i++)
    cin>>p[i];
sort(b, b+n);
sort(p, p+m);
int start=0, finish=min(n, m), mid;
do{
    mid=(start+finish)/2;
    int tot=a;
    for(int i=0; i<mid; i++){
        int hi=b[n-mid+i]-p[i];
        hi=min(hi, 0);
        tot+=hi;
    }
    if(tot>=0)
        start=mid+1;
    else
        finish=mid-1;
}while(start<=finish);
for(int i=min(mid+1, min(n, m)); i>=mid-1; i--){
    int tot=a, su=0;
    for(int j=0; j<i; j++){
        int hi=b[n-i+j]-p[j];
        su+=p[j];
        hi=min(hi, 0);
        tot+=hi;
    }
    if(tot>=0){
        cout<<i<<" "<<max(su-a, 0);
        return 0;
    }
}
return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int N = 1e5+100;
int n,m,a,b[N],p[N];
bool ok(int mid)
{
    long long sum=0;
    for(int i=mid-1; i>=0; i--)
        if(p[i]>b[n-1+i-mid-1])
            sum+=p[i]-b[(n-1)+i-(mid-1)];

    if(sum>a)
        return 0;
    else
        return 1;
}
int main()
{
    scanf("%d%d%d",&n,&m,&a);
    for(int i=0; i<n; i++)
        scanf("%d",b+i);
    for(int i=0; i<m; i++)
        scanf("%d",p+i);
    sort(b,b+n);
    sort(p,p+m);
    int l=0,r=m;
    while(r>l)
    {
        int mid = (r+l+1)/2;
        if(ok(mid))
            l=mid;
        else
            r=mid-1;
    }
    int res=-a;
    for(int i=0; i<l; i++)
        res+=p[i];

    printf("%d %d",l,max(res,0));

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int N = 1e5+100;
int n,m,a,b[N],p[N];
bool ok(int mid)
{
    long long sum=0;
    for(int i=mid-1; i>=0; i--)
        if(p[i]>b[(n-1)+i-(mid-1)])
            sum+=p[i]-b[(n-1)+i-(mid-1)];

    if(sum>a)
        return 0;
    else
        return 1;
}
int main()
{
    scanf("%d%d%d",&n,&m,&a);
    for(int i=0; i<n; i++)
        scanf("%d",b+i);
    for(int i=0; i<m; i++)
        scanf("%d",p+i);
    sort(b,b+n);
    sort(p,p+m);
    int l=0,r=m;
    while(r>l)
    {
        int mid = (r+l+1)/2;
        if(ok(mid))
            l=mid;
        else
            r=mid-1;
    }
    int res=-a;
    for(int i=0; i<l; i++)
        res+=p[i];

    printf("%d %d",l,max(res,0));

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int N = 1e5+100;
int n,m,a,b[N],p[N];
bool ok(int mid)
{
    long long sum=0;
    for(int i=mid-1; i>=0; i--)
        if(p[i]>b[(n-1)+i-(mid-1)])
            sum+=p[i]-b[(n-1)+i-(mid-1)];

    if(sum>a)
        return 0;
    else
        return 1;
}
int main()
{
    scanf("%d%d%d",&n,&m,&a);
    for(int i=0; i<n; i++)
        scanf("%d",b+i);
    for(int i=0; i<m; i++)
        scanf("%d",p+i);
    sort(b,b+n);
    sort(p,p+m);
    int l=0,r=min(n,m);
    while(r>l)
    {
        int mid = (r+l+1)/2;
        if(ok(mid))
            l=mid;
        else
            r=mid-1;
    }
    int res=-a;
    for(int i=0; i<l; i++)
        res+=p[i];

    printf("%d %d",l,max(res,0));

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e5+10;
int n,m,a,b[N],p[N];

bool f[N];
int aa=a;
bool ok(int mid)
{
    memset(f,0,sizeof f);
    int cnt=0;
    aa=a;
    for(int i=0;i<m;i++){
        if(cnt==mid) break;
        for(int j=0;j<n;j++){
            if(!f[j] && b[j]+aa>=p[i]){
                f[j]=1;
                aa-= (p[i]-b[j]);
                cnt++;
                break;
            }
        }
    }
    if(cnt>=mid) return 1;
    else return 0;

}

int main()
{
    scanf("%d%d%d",&n,&m,&a);
    for(int i=0; i<n; i++)
        scanf("%d",b+i);
    for(int i=0; i<m; i++)
        scanf("%d",p+i);
    sort(b,b+n);
    sort(p,p+m);
    int l=0,r=m;
    while(r>l)
    {
        int mid = (r+l+1)/2;
        if(ok(mid))
            l=mid;
        else
            r=mid-1;
    }
    int res=0;
    for(int i=0;i<n;i++)
        if(f[i]) res+=b[i];

    printf("%d %d",l,max(res-aa,0));

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int N = 1e5+100;
int n,m,a,b[N],p[N];
bool ok(int mid)
{
    long long sum=0;
    for(int i=mid; i>=1; i--)
        if(p[i]>b[n+i-mid])
            sum+=p[i]-b[n+i-mid];

    if(sum>a)
        return 0;
    else
        return 1;
}
int main()
{
    scanf("%d%d%d",&n,&m,&a);
    for(int i=1; i<=n; i++)
        scanf("%d",b+i);
    for(int i=1; i<=m; i++)
        scanf("%d",p+i);
    sort(b+1,b+n+1);
    sort(p+1,p+m+1);
    int l=0,r=m;
    while(r>l)
    {
        int mid = (r+l+1)/2;
        if(ok(mid))
            l=mid;
        else
            r=mid-1;
    }
    int res=-a;
    for(int i=1; i<=l; i++)
        res+=p[i];

    printf("%d %d",l,max(res,0));

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int n,m,a,b,p,s1=0,s2=0,t;
vector<int>v,v1;

int bike(int k,int key)
{
    int low=0,high=k-1,mid;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(key<v1[mid])
            high=mid-1;
        else
            low=mid+1;
    }
    return low;
}

int main()
{
    cin>>n>>m>>a;
    for(int i=1; i<=n; i++)
    {
        cin>>b;
        s1=s1+b;
    }
    for(int i=1; i<=m; i++)
    {
        cin>>p;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    if(n<m)
    {
        for(int i=0; i<n; i++)
        {
            s2=s2+v[i];
            v1.push_back(s2);
        }
        t=bike(n,s1+a);
        if(t==0)
            cout<<0<<" "<<0<<endl;
        else
            cout<<t<<" "<<v1[t-1]-a<<endl;
    }
    else
    {
        for(int i=0; i<m; i++)
        {
            s2=s2+v[i];
            v1.push_back(s2);
        }
        t=bike(m,s1+a);
        if(t==0)
            cout<<0<<" "<<0<<endl;
        else
            cout<<t<<" "<<v1[t-1]-a<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int n,m,a,b,p,s1=0,s2=0,s3=0,s4=0,t,c;
vector<int>v,v1,v2;

int bike(int k,int key)
{
    int low=0,high=k-1,mid;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(key<v1[mid])
            high=mid-1;
        else
            low=mid+1;
    }
    return low;
}

int main()
{
    cin>>n>>m>>a;
    for(int i=1; i<=n; i++)
    {
        cin>>b;
        s1=s1+b;
        v2.push_back(b);
    }
    sort(v2.begin(),v2.end());
    for(int i=1; i<=m; i++)
    {
        cin>>p;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    if(n<m)
    {
        for(int i=0; i<n; i++)
        {
            s2=s2+v[i];
            v1.push_back(s2);
        }
        t=bike(n,s1+a);
        c=v1[t-1]-a;
        for(int i=n-1; i>=n-t; i--)
        {
            s3=s3+v2[i];
            /*if(v2[i]<c/t)
            {
                t--;
                c=v1[t-1]-a;
                i=n;
                s3=0;
            }*/
        }
        while(1)
        {
            if(s3<c)
            {
                t--;
                c=v1[t-1]-a;
                s3=s3-v2[n-t-1];
            }
            else
                break;
        }
        s4=a;
        for(int i=n-1,j=t-1; i>=n-t,j>=0; i--,j--)
        {
            if(v2[i]<v[j])
            {
                if(s4>=0)
                    s4=s4-v[j]+v2[i];
                if(s4<0)
                {
                    t--;
                    c=v1[t-1]-a;
                    s4=a;
                    i=n;
                    j=t;
                }
            }
        }
        if(t==0)
            cout<<0<<" "<<0<<endl;
        else if(c<0)
            cout<<t<<" "<<0<<endl;
        else
            cout<<t<<" "<<c<<endl;
    }
    else
    {
        for(int i=0; i<m; i++)
        {
            s2=s2+v[i];
            v1.push_back(s2);
        }
        t=bike(m,s1+a);
        c=v1[t-1]-a;
        for(int i=n-1; i>=n-t; i--)
        {
            s3=s3+v2[i];
            /*if(v2[i]<c/t)
            {
                t--;
                c=v1[t-1]-a;
                i=n;
                s3=0;
            }*/
        }
        //cout<<t<<" "<<c<<endl;
        while(1)
        {
            if(s3<c)
            {
                t--;
                c=v1[t-1]-a;
                s3=s3-v2[n-t-1];
            }
            else
                break;
        }
        //cout<<t<<" "<<c<<endl;
        s4=a;
        for(int i=n-1,j=t-1; i>=n-t,j>=0; i--,j--)
        {
            if(v2[i]<v[j])
            {
                if(s4>=0)
                    s4=s4-v[j]+v2[i];
                if(s4<0)
                {
                    t--;
                    c=v1[t-1]-a;
                    s4=a;
                    i=n;
                    j=t;
                }
            }
        }
        if(t==0)
            cout<<0<<" "<<0<<endl;
        else if(c<0)
            cout<<t<<" "<<0<<endl;
        else
            cout<<t<<" "<<c<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

int n,m,a,b,p,s1=0,s2=0,s3=0,t,c;
vector<int>v,v1,v2;

int bike(int k,int key)
{
    int low=0,high=k-1,mid;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(key<v1[mid])
            high=mid-1;
        else
            low=mid+1;
    }
    return low;
}

int main()
{
    cin>>n>>m>>a;
    for(int i=1; i<=n; i++)
    {
        cin>>b;
        s1=s1+b;
        v2.push_back(b);
    }
    sort(v2.begin(),v2.end());
    for(int i=1; i<=m; i++)
    {
        cin>>p;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    if(n<m)
    {
        for(int i=0; i<n; i++)
        {
            s2=s2+v[i];
            v1.push_back(s2);
        }
        t=bike(n,s1+a);
        c=v1[t-1]-a;
        for(int i=n-1; i>=n-t; i--)
            s3=s3+v2[i];
        while(1)
        {
            if(s3<c)
            {
                t--;
                c=v1[t-1]-a;
                s3=s3-v2[n-t-1];
            }
            else
                break;
        }
        if(t==0)
            cout<<0<<" "<<0<<endl;
        else if(c<0)
            cout<<t<<" "<<0<<endl;
        else
            cout<<t<<" "<<c<<endl;
    }
    else
    {
        for(int i=0; i<m; i++)
        {
            s2=s2+v[i];
            v1.push_back(s2);
        }
        t=bike(m,s1+a);
        c=v1[t-1]-a;
        for(int i=n-1; i>=n-t; i--)
            s3=s3+v2[i];
        while(1)
        {
            if(s3<c)
            {
                t--;
                c=v1[t-1]-a;
                s3=s3-v2[n-t-1];
            }
            else
                break;
        }
        if(t==0)
            cout<<0<<" "<<0<<endl;
        else if(c<0)
            cout<<t<<" "<<0<<endl;
        else
            cout<<t<<" "<<c<<endl;
    }
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int pm[N], b[N];

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

  for(int i = 0; i < n; i++)
    cin >> pm[i];

  for(int i = 0; i < m; i++)
    cin >> b[i];

  sort(pm, pm + n, greater<int>());
  sort(b, b + m, greater<int>());

  int i = 0, j = min(n, m) + 1;
  while(i != j){
    int mid = (i + j)/2;
    int tmp = a;

    for(int i = 0; i < mid; i++){
      tmp = tmp - max(0, b[m - mid + i] - pm[i]);
    }

    if(tmp < 0) j = mid;
    else i = mid + 1;
  }

  int ans = i - 1;
  ll mn = 0;

  for(int i = 0; i < ans; i++){
    a -= max(0, b[m - ans + i] - pm[i]);
    mn += min(pm[i], b[m - ans + i]);
  }

  cout << ans << ' ' << max(0, mn - a) << endl;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N = 1e5 + 5;
ll pm[N], b[N];

int main(){
  ll n, m, a;
  cin >> n >> m >> a;

  for(ll i = 0; i < n; i++)
    cin >> pm[i];

  for(ll i = 0; i < m; i++)
    cin >> b[i];

  sort(pm, pm + n, greater<ll>());
  sort(b, b + m, greater<ll>());

  ll i = 0, j = min(n, m) + 1;
  while(i != j){
    ll mid = (i + j)/2;
    ll tmp = a;

    for(ll i = 0; i < mid; i++){
      tmp = tmp - max(0ll, b[m - mid + i] - pm[i]);
    }

    if(tmp < 0) j = mid;
    else i = mid + 1;
  }

  ll ans = i - 1;
  ll mn = 0;

  for(ll i = 0; i < ans; i++){
    a -= max(0ll, b[m - ans + i] - pm[i]);
    mn += min(pm[i], b[m - ans + i]);
  }

  cout << ans << ' ' << max(0ll, mn - a) << endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int pm[N], b[N];

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

  for(int i = 0; i < n; i++)
    cin >> pm[i];

  for(int i = 0; i < m; i++)
    cin >> b[i];

  sort(pm, pm + n, greater<int>());
  sort(b, b + m, greater<int>());

  int i = 0, j = min(n, m) + 1;
  while(i != j){
    int mid = (i + j)/2;
    int tmp = a;

    for(int i = 0; i < mid; i++){
      tmp = tmp - max(0, b[m - mid + i] - pm[i]);
    }

    if(tmp < 0) j = mid;
    else i = mid + 1;
  }

  int ans = i - 1;
  int mn = 0;

  for(int i = 0; i < ans; i++){
    a -= max(0, b[m - ans + i] - pm[i]);
    mn += min(pm[i], b[m - ans + i]);
  }

  cout << ans << ' ' << max(0, mn - a) << endl;
}


#include<bits/stdc++.h>
using namespace std;
const ll N = 1e5 + 5;
ll pm[N], b[N];

int main(){
  ll n, m, a;
  cin >> n >> m >> a;

  for(ll i = 0; i < n; i++)
    cin >> pm[i];

  for(ll i = 0; i < m; i++)
    cin >> b[i];

  sort(pm, pm + n, greater<ll>());
  sort(b, b + m, greater<ll>());

  ll i = 0, j = min(n, m) + 1;
  while(i != j){
    ll mid = (i + j)/2;
    ll tmp = a;

    for(ll i = 0; i < mid; i++){
      tmp = tmp - max(0, b[m - mid + i] - pm[i]);
    }

    if(tmp < 0) j = mid;
    else i = mid + 1;
  }

  ll ans = i - 1;
  ll mn = 0;

  for(ll i = 0; i < ans; i++){
    a -= max(0, b[m - ans + i] - pm[i]);
    mn += min(pm[i], b[m - ans + i]);
  }

  cout << ans << ' ' << max(0, mn - a) << endl;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N = 1e5 + 5;
ll pm[N], b[N];

int main(){
  ll n, m, a;
  cin >> n >> m >> a;

  for(ll i = 0; i < n; i++)
    cin >> pm[i];

  for(ll i = 0; i < m; i++)
    cin >> b[i];

  sort(pm, pm + n, greater<ll>());
  sort(b, b + m, greater<ll>());

  ll i = 0, j = min(n, m) + 1;
  while(i != j){
    ll mid = (i + j)/2;
    ll tmp = a;

    for(ll i = 0; i < mid; i++){
      tmp = tmp - max(0, b[m - mid + i] - pm[i]);
    }

    if(tmp < 0) j = mid;
    else i = mid + 1;
  }

  ll ans = i - 1;
  ll mn = 0;

  for(ll i = 0; i < ans; i++){
    a -= max(0, b[m - ans + i] - pm[i]);
    mn += min(pm[i], b[m - ans + i]);
  }

  cout << ans << ' ' << max(0, mn - a) << endl;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int pm[N], b[N];

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

  for(int i = 0; i < n; i++)
    cin >> pm[i];

  for(int i = 0; i < m; i++)
    cin >> b[i];

  sort(pm, pm + n, greater<int>());
  sort(b, b + m, greater<int>());

  int i = 0, j = min(n, m) + 1;
  while(i != j){
    int mid = (i + j)/2;
    int tmp = a;

    for(int i = 0; i < mid; i++){
      tmp = tmp - max(0, b[m - mid + i] - pm[i]);
    }

    if(tmp < 0) j = mid;
    else i = mid + 1;
  }

  int ans = i - 1;
  ll mn = 0;

  for(int i = 0; i < ans; i++){
    a -= max(0, b[m - ans + i] - pm[i]);
    mn += min(pm[i], b[m - ans + i]);
  }

  cout << ans << ' ' << max(0ll, mn - a) << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
	long long n, m, a0; cin >> n >> m >> a0;
	vector <long long> b(n), p(m);
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < m; ++i) cin >> p[i];
	sort(b.begin(), b.end());
	sort(p.begin(), p.end());

	long long lower = 0, upper = min(m + 1, n + 1);
 	while (upper - lower > 1) {
		long long a = a0;
		long long mid = (lower + upper) / 2;
		long long res = 0;
		for (int i = n - mid; i < n; ++i) {
			res += min(b[i], p[i - (n - mid)]);
			a -= max(0 * 1LL, p[i - (n - mid)] - b[i]);
		}
		if (a >= 0)
			lower = mid;
		else upper = mid;
	}
	long long s = 0;
	for (int i = 0; i < lower; ++i) {
		s += min(b[i], p[i]);
		a0 -= max(0 * 1LL, p[i] - b[i]);
	}
	s -= a0;
	cout << lower << " " << max(0 * 1LL, s) << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

bool cmp (pair <int, int> a, pair <int, int> b) {
	return (max(0, a.second - a.first) < max(0, b.second - b.first)) ||
				 (max(0, a.second - a.first) == max(0, b.second - b.first) && a.second < b.second);
}

int main()
{
  IO;
	int n, m, a0; cin >> n >> m >> a0;
	vector <int> b(n), p(m);
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < m; ++i) cin >> p[i];
	sort(b.rbegin(), b.rend());
	sort(p.begin(), p.end());

	int lower = 0, upper = m + 1;
 	while (upper - lower > 1) {
		int a = a0;
		int mid = (lower + upper) / 2;
		int res = 0;
		for (int i = 0; i < mid; ++i) {
			res += min(b[i], p[i]);
			a -= max(0, p[i] - b[i]);
		}
		if (a >= 0)
			lower = mid;
		else upper = mid;
	}
	int s = 0;
	for (int i = 0; i < lower; ++i) {
		s += min(b[i], p[i]);
		a0 -= max(0, p[i] - b[i]);
	}
	s -= a0;
	cout << lower << " " << s << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
	long long n, m, a0; cin >> n >> m >> a0;
	vector <long long> b(n), p(m);
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < m; ++i) cin >> p[i];
	sort(b.begin(), b.end());
	sort(p.begin(), p.end());

	long long lower = 0, upper = min(m + 1, n + 1);
 	while (upper - lower > 1) {
		long long a = a0;
		long long mid = (lower + upper) / 2;
		long long res = 0;
		for (int i = n - mid; i < n; ++i) {
			res += min(b[i], p[i - (n - mid)]);
			a -= max(0, p[i - (n - mid)] - b[i]);
		}
		if (a >= 0)
			lower = mid;
		else upper = mid;
	}
	long long s = 0;
	for (int i = 0; i < lower; ++i) {
		s += min(b[i], p[i]);
		a0 -= max(0, p[i] - b[i]);
	}
	s -= a0;
	cout << lower << " " << s << endl;

  return 0;
}