n = readline.to_i
h = {}
h.default = 0
(1..n).each do
  q_type, q_key = readline.split.map(&:strip)

  t=0
  (0...q_key.size).each do |i|
    t *= 2
    t += q_key[i].ord % 2
  end

  if q_type == '+'
    h[t] += 1
  elsif q_type == '-'
    h[t] -= 1
  else
    puts h[t]
  end
end


import time

def convert_to_01(value):
    result = []

    for digit in value:
        if int(digit) % 2 == 0:
            result.append(0)
        else:
            result.append(1)

    return ([0] * (18 - len(result)) + result)[::-1]

class Tree(object):
    def __init__(self):
        self.array = [0] * 5 + [0] * (2 ** 18)

    def insert(self, value, root=1):
        self.array[root] += 1

        if not value:
            return

        new_root = root * 2 if value[0] == 0 else (root * 2 + 1)
        self.insert(value[1:], new_root)

    def remove(self, value, root=1):
        self.array[root] -= 1

        if not value:
            return

        new_root = root * 2 if value[0] == 0 else (root * 2 + 1)
        self.remove(value[1:], new_root)

    def query(self, template, root=1):
        if len(template) == 1:
            return self.array[root * 2] if template[0] == 0 else self.array[root * 2 + 1]

        new_root = root * 2 if template[0] == 0 else (root * 2 + 1)
        return self.query(template[1:], new_root)

tree = Tree()

for _ in xrange(int(raw_input())):
    command, value = raw_input().split()

    if command == '+':
        tree.insert(convert_to_01(value))
    elif command == '-':
        tree.remove(convert_to_01(value))
    else:
        template = map(int, ([0] * (18 - len(value)) + list(value))[::-1])
        print tree.query(template)


import time

def convert_to_01(value):
    result = []

    for digit in value:
        if int(digit) % 2 == 0:
            result.append(0)
        else:
            result.append(1)

    return ([0] * (18 - len(result)) + result)[::-1]

class Tree(object):
    def __init__(self):
        self.array = [0] + [0] * (2 ** 19)

    def insert(self, value):

        end_idx = 1
        for i in value:
            end_idx *= 2
            if i:
                end_idx += 1

        self.array[end_idx] += 1

    def remove(self, value):
        end_idx = 1
        for i in value:
            end_idx *= 2
            if i:
                end_idx += 1

        self.array[end_idx] -= 1

    def query(self, template):

        end_idx = 1
        for i in template:
            end_idx *= 2
            if i:
                end_idx += 1

        return self.array[end_idx]

tree = Tree()

for _ in xrange(int(raw_input())):
    command, value = raw_input().split()

    if command == '+':
        tree.insert(convert_to_01(value))
    elif command == '-':
        tree.remove(convert_to_01(value))
    else:
        template = map(int, ([0] * (18 - len(value)) + list(value))[::-1])
        print tree.query(template)


# DISCLAIMER: Borrowed idea from other submission
odds = '13579'
counts = [0] * (2**18 + 1)

for _ in xrange(int(raw_input())):
    command, value = raw_input().split()
    if command == '+':
        value = int(''.join([str(int(i in odds)) for i in value]), base=2)
        counts[value] += 1
    elif command == '-':
        value = int(''.join([str(int(i in odds)) for i in value]), base=2)
        counts[value] -= 1
    else:
        print counts[int(value, base=2)]


# DISCLAIMER: Borrowed idea from other submission
odds = '13579'
counts = [0] * (2**18 + 1)

for _ in xrange(int(raw_input())):
    command, value = raw_input().split()

    value = int(''.join(['1' if i in odds else '0' for i in value]), base=2)

    if command == '+':
        counts[value] += 1
    elif command == '-':
        counts[value] -= 1
    else:
        print counts[value]


import time

def convert_to_01(value):
    result = []

    for digit in value:
        if int(digit) % 2 == 0:
            result.append(0)
        else:
            result.append(1)

    return ([0] * (18 - len(result)) + result)[::-1]

class Tree(object):
    def __init__(self):
        self.array = [0] + [0] * (2 ** 19 - 262144)

    def insert(self, value):

        end_idx = 1
        for i in value:
            end_idx *= 2
            if i:
                end_idx += 1

        self.array[end_idx - 262144] += 1

    def remove(self, value):
        end_idx = 1
        for i in value:
            end_idx *= 2
            if i:
                end_idx += 1

        self.array[end_idx - 262144] -= 1

    def query(self, template):

        end_idx = 1
        for i in template:
            end_idx *= 2
            if i:
                end_idx += 1

        return self.array[end_idx - 262144]

tree = Tree()

for _ in xrange(int(raw_input())):
    command, value = raw_input().split()

    if command == '+':
        tree.insert(convert_to_01(value))
    elif command == '-':
        tree.remove(convert_to_01(value))
    else:
        template = map(int, ([0] * (18 - len(value)) + list(value))[::-1])
        print tree.query(template)


import time

def convert_to_01(value):
    result = []

    for digit in value:
        if int(digit) % 2 == 0:
            result.append(0)
        else:
            result.append(1)

    return ([0] * (18 - len(result)) + result)[::-1]

class Tree(object):
    def __init__(self):
        self.array = [0] + [0] * (2 ** 19)

    def insert(self, value, root=1):
        self.array[root] += 1

        if not value:
            return

        new_root = root * 2 if value[0] == 0 else (root * 2 + 1)
        self.insert(value[1:], new_root)

    def remove(self, value, root=1):
        self.array[root] -= 1

        if not value:
            return

        new_root = root * 2 if value[0] == 0 else (root * 2 + 1)
        self.remove(value[1:], new_root)

    def query(self, template, root=1):
        if len(template) == 1:
            return self.array[root * 2] if template[0] == 0 else self.array[root * 2 + 1]

        new_root = root * 2 if template[0] == 0 else (root * 2 + 1)
        return self.query(template[1:], new_root)

tree = Tree()

for _ in xrange(int(raw_input())):
    command, value = raw_input().split()

    if command == '+':
        tree.insert(convert_to_01(value))
    elif command == '-':
        tree.remove(convert_to_01(value))
    else:
        template = map(int, ([0] * (18 - len(value)) + list(value))[::-1])
        print tree.query(template)


from collections import defaultdict
t = int(raw_input())
pat = defaultdict(tuple) # holds odd/even pattern
#  odd = [ 0 for i in range(19) ]
#  even = [ 0 for i in range(19) ]
#  print len(odd), len(even)

def getS2Pattern(s):
    #  cur_len = len(s)
    #  zeros = 19 - cur_len
    #  news = '0'*zeros + s
    news = s.zfill(19)
    return tuple(map(int, list(news)))

def getSPattern(s):
    #  cur_len = len(s)
    #  zeros = 19 - cur_len
    #  news = '0'*zeros + s
    news = s.zfill(19)
    patlist = [ 0 if (int(news[i])%2 == 0) else 1   for i in range(19) ]
    return tuple(patlist)
'''    for i in range(19):
        c = int(news[i])
        if c%2 == 0:
            patlist.append(0)
            #  even[i] += 1
        else:
            patlist.append(1)
            #  odd[i] += 1'''

def getPattern(n):
    return getSPattern(str(n))

for i in range(0, t):
    oper, num = raw_input().strip().split(' ')
    #  print oper, num
    if oper == '+' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] += 1
        else:
            pat[pattern] = 1
    elif oper == '-' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] =  max( pat[pattern] - 1, 0)
        else:
            pass
        # do nothing, problem question gaurantees this wont be the case
    elif oper == '?' :
        print pat.get(getS2Pattern(num) , 0 )


t = int(raw_input())
m = {}
pat = {}
odd = [ 0 for i in range(19) ]
even = [ 0 for i in range(19) ]
#  print len(odd), len(even)

def getSPattern(s):
    cur_len = len(s)
    zeros = 19 - cur_len
    news = '0'*zeros + s
    patlist = []
    for i in range(19):
        c = int(news[i])
        if c%2 == 0:
            patlist.append(0)
            #  even[i] += 1
        else:
            patlist.append(1)
            #  odd[i] += 1
    return tuple(patlist)

def getPattern(n):
    s = str(n)
    cur_len = len(s)
    zeros = 19 - cur_len
    news = '0'*zeros + s
    patlist = []
    for i in range(19):
        c = int(news[i])
        if c%2 == 0:
            patlist.append(0)
            #  even[i] += 1
        else:
            patlist.append(1)
            #  odd[i] += 1
    return tuple(patlist)

for i in range(0, t):
    oper, num = raw_input().strip().split(' ')
    #  print oper, num
    if oper == '+' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] += 1
        else:
            pat[pattern] = 1

        num = int(num)
        if num in m:
            m[num] += 1
        else:
            m[num] = 1
        pass

    elif oper == '-' :
        pattern = getPattern(num)
        pat[pattern] =  max( pat[pattern] - 1, 0)
        num = int(num)
        m[num] -= 1
        if m[num] == 0 : #.get(num, 0) == 1 :
            m.pop(num, None)
        # do nothing, problem question gaurantees this wont be the case
        pass

    elif oper == '?' :
        pattern = getSPattern(num)
        print pat[pattern]
        pass


from collections import defaultdict
t = int(raw_input())
pat = defaultdict(tuple) # holds odd/even pattern
#  odd = [ 0 for i in range(19) ]
#  even = [ 0 for i in range(19) ]
#  print len(odd), len(even)

def getSPattern(s):
    cur_len = len(s)
    zeros = 19 - cur_len
    news = '0'*zeros + s
    patlist = []
    for i in range(19):
        c = int(news[i])
        if c%2 == 0:
            patlist.append(0)
            #  even[i] += 1
        else:
            patlist.append(1)
            #  odd[i] += 1
    return tuple(patlist)

def getPattern(n):
    s = str(n)
    return getSPattern(s)

for i in range(0, t):
    oper, num = raw_input().strip().split(' ')
    #  print oper, num
    if oper == '+' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] += 1
        else:
            pat[pattern] = 1

    elif oper == '-' :
        pattern = getPattern(num)
        pat[pattern] =  max( pat[pattern] - 1, 0)
        # do nothing, problem question gaurantees this wont be the case
        pass

    elif oper == '?' :
        pattern = getSPattern(num)
        print pat[pattern]
        pass


def getPattern(s):
    return ''.join(list(s.zfill(19)))

def getSPattern(s):
    patlist = ['0' if c in ['0', '2', '4', '6', '8'] else '1' for c in s]
    return "".join(patlist).zfill(19)

t = int(raw_input())
pat = dict()  # holds strings as keys and int as value

for i in range(0, t):
    oper, num = raw_input().strip().split(' ')

    if oper == '+':
        pattern = getSPattern(str(num))
        if pattern in pat:
            pat[pattern] += 1
        else:
            pat[pattern] = 1

    elif oper == '-':
        pattern = getSPattern(str(num))
        pat[pattern] = max(pat[pattern] - 1, 0)

    elif oper == '?':
        print pat.get(getPattern(num), 0)


from collections import defaultdict
t = int(raw_input())
pat = defaultdict(tuple) # holds odd/even pattern
#  odd = [ 0 for i in range(19) ]
#  even = [ 0 for i in range(19) ]
#  print len(odd), len(even)

def getS2Pattern(s):
    cur_len = len(s)
    zeros = 19 - cur_len
    news = '0'*zeros + s
    return tuple(map(int, list(news)))

def getSPattern(s):
    cur_len = len(s)
    zeros = 19 - cur_len
    news = '0'*zeros + s
    patlist = [ 0 if (int(news[i])%2 == 0) else 1   for i in range(19) ]
    return tuple(patlist)
'''    for i in range(19):
        c = int(news[i])
        if c%2 == 0:
            patlist.append(0)
            #  even[i] += 1
        else:
            patlist.append(1)
            #  odd[i] += 1'''

def getPattern(n):
    s = str(n)
    return getSPattern(s)

for i in range(0, t):
    oper, num = raw_input().strip().split(' ')
    #  print oper, num
    if oper == '+' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] += 1
        else:
            pat[pattern] = 1

    elif oper == '-' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] =  max( pat[pattern] - 1, 0)
        else:
            pass
        # do nothing, problem question gaurantees this wont be the case
        pass

    elif oper == '?' :
        pattern = getS2Pattern(num)
        print pat[pattern]
        pass


from collections import defaultdict
t = int(raw_input())
pat = defaultdict(tuple) # holds odd/even pattern
#  odd = [ 0 for i in range(19) ]
#  even = [ 0 for i in range(19) ]
#  print len(odd), len(even)

def getSPattern(s):
    cur_len = len(s)
    zeros = 19 - cur_len
    news = '0'*zeros + s
    patlist = []
    for i in range(19):
        c = int(news[i])
        if c%2 == 0:
            patlist.append(0)
            #  even[i] += 1
        else:
            patlist.append(1)
            #  odd[i] += 1
    return tuple(patlist)

def getPattern(n):
    s = str(n)
    return getSPattern(s)

for i in range(0, t):
    oper, num = raw_input().strip().split(' ')
    #  print oper, num
    if oper == '+' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] += 1
        else:
            pat[pattern] = 1

    elif oper == '-' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] =  max( pat[pattern] - 1, 0)
        else:
            pass
        # do nothing, problem question gaurantees this wont be the case
        pass

    elif oper == '?' :
        pattern = getSPattern(num)
        print pat[pattern]
        pass


from collections import defaultdict
t = int(raw_input())
pat = defaultdict(str) # holds odd/even pattern
#  odd = [ 0 for i in range(19) ]
#  even = [ 0 for i in range(19) ]
#  print len(odd), len(even)

def getS2Pattern(s):
    news = s.zfill(19)
    return ''.join(list(news))
    #  cur_len = len(s)
    #  zeros = 19 - cur_len
    #  news = '0'*zeros + s
    #  return tuple(map(int, list(news)))

def getSPattern(s):
    #  cur_len = len(s)
    #  zeros = 19 - cur_len
    #  news = '0'*zeros + s
    news = s.zfill(19)
    patlist = [ '0' if (int(news[i])%2 == 0) else '1'   for i in range(19) ]
    return "".join(patlist)
    #  return tuple(patlist)

def getPattern(n):
    return getSPattern(str(n))

for i in range(0, t):
    oper, num = raw_input().strip().split(' ')
    #  print oper, num
    if oper == '+' :
        pattern = getPattern(num)
        if pattern in pat:
            pat[pattern] += 1
        else:
            pat[pattern] = 1
    elif oper == '-' :
        pattern = getPattern(num)
        #  if pattern in pat:
        pat[pattern] =  max( pat[pattern] - 1, 0)
        #  else:
            #  pass
        # do nothing, problem question gaurantees this wont be the case
    elif oper == '?' :
        print pat.get(getS2Pattern(num) , 0 )


//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>

using namespace std;

#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 1000000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

priority_queue <pair<double, int> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

pair<double, int> tree[10 * MAX+9];

void update(int id, int l, int r, int q, double v)
{
   if(l >= q && r <= q)
   {
      tree[id] = MP(q, v) ;
      return;
   }

   int mid = (l+r) >> 1;

   if(q <= mid) update(2*id, l, mid, q, v);
   if(q > mid) update(2*id+1, mid+1, r, q, v);

   if(tree[2*id].second < tree[2*id + 1].second) tree[id] = tree[2*id];
   else tree[id] = tree[2*id + 1];
}

pair<int, double> query(int id, int l, int r, int ql, int qr)
{
   if(l >= ql && r <= qr) return tree[id];

   int mid = (l+r)>>1;
   pair<int, double> L = MP(0, 10000000), R = MP(0, 10000000);

   if(ql <= mid) L = query(2*id, l, mid, ql, qr);
   if(qr > mid) R = query(2*id+1, mid+1, r, ql, qr);

   if(L.second < R.second) return L;
   return R;
}

Long check(Long curr, Long n, Long m)
{
    int i, temp;
    pair<double, int> II;
    double val;

    while(!sett.empty()) sett.pop();
    for(i=1;i<=n;i++) cnt[i] = 0;

    for(i=1;i<=n;i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val > 1000000) val = 1000000;
        update(1,1,n,i,val);
    }

    for(i=2;i<=m && !sett.empty();i++)
    {
        II = query(1,1,n,1,n);
        temp = II.first;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        cnt[temp]++;

        if(val > 1000000) val = 1000000;
        update(1,1,n,temp,val);
    }

    for(i=1;i<=n;i++)
    {
        if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    }

    return 1;

}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;
    Long inf = 2;
    for(i=1;i<=12;i++) inf *= 10;

    cin>>n>>m;

    for(i=1;i<=n;i++) scanf("%lld", &ar[i]);
    for(i=1;i<=n;i++) scanf("%lld", &pr[i]);

    ans = BS(0, inf, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


//Bismillahir Rahmanir Rahim
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 200000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

priority_queue <pair<double, int> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

Long check(Long curr, Long n, Long m)
{
    int i, temp;
    pair<double, int> II;
    double val;

    while(!sett.empty()) sett.pop();
    for(i=1; i<=n; i++) cnt[i] = 0;

    for(i=1; i<=n; i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val > m + 2) continue;
        sett.push(MP(-val, i));
    }

    for(i=2; i<=m && !sett.empty(); i++)
    {
        II = sett.top();
        sett.pop();

        temp = II.second;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        cnt[temp]++;

        if(val > m + 2) continue;
        sett.push(MP(-val, temp));
    }

    for(i=1; i<=n; i++) if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    return 1;
}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;
    Long inf = 2;
    for(i=1; i<=12; i++) inf *= 10;

    cin>>n>>m;

    for(i=1; i<=n; i++) scanf("%lld", &ar[i]);
    for(i=1; i<=n; i++) scanf("%lld", &pr[i]);

    ans = BS(0, inf, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


//Bismillahir Rahmanir Rahim
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 1000000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

priority_queue <pair<double, int> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

Long check(Long curr, Long n, Long m)
{
    int i, temp;
    pair<double, int> II;
    double val;

    while(!sett.empty()) sett.pop();
    for(i=1;i<=n;i++) cnt[i] = 0;

    for(i=1;i<=n;i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val > 1000000) continue;
        sett.push(MP(-val, i));
    }

    for(i=2;i<=m && !sett.empty();i++)
    {
        II = sett.top();
        sett.pop();

        temp = II.second;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        cnt[temp]++;

        if(val > 1000000) continue;
        sett.push(MP(-val, temp));
    }

    for(i=1;i<=n;i++)
    {
        if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    }

    return 1;

}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;
    Long inf = 2;
    for(i=1;i<=12;i++) inf *= 10;

    cin>>n>>m;

    for(i=1;i<=n;i++) scanf("%lld", &ar[i]);
    for(i=1;i<=n;i++) scanf("%lld", &pr[i]);

    ans = BS(0, inf, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


//Bismillahir Rahmanir Rahim
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 2000000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

priority_queue <pair<double, int> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

Long check(Long curr, Long n, Long m)
{
    int i, temp;
    pair<double, int> II;
    double val;

    while(!sett.empty()) sett.pop();
    for(i=1; i<=n; i++) cnt[i] = 0;

    for(i=1; i<=n; i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val > m + 2) continue;
        sett.push(MP(-val, i));
    }

    for(i=2; i<=m && !sett.empty(); i++)
    {
        II = sett.top();
        sett.pop();

        temp = II.second;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        cnt[temp]++;

        if(val > m + 2) continue;
        sett.push(MP(-val, temp));
    }

    for(i=1; i<=n; i++) if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    return 1;
}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;
    Long inf = 2;
    for(i=1; i<=12; i++) inf *= 10;

    cin>>n>>m;

    for(i=1; i<=n; i++) scanf("%lld", &ar[i]);
    for(i=1; i<=n; i++) scanf("%lld", &pr[i]);

    ans = BS(0, inf, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


//Bismillahir Rahmanir Rahim
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 1000000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

set<pair<double, int> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

Long check(Long curr, Long n, Long m)
{
    int i;
    int temp;
    pair<double, int> II;
    double val;

    sett.clear();
    for(i=1;i<=n;i++) cnt[i] = 0;

    for(i=1;i<=n;i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val > 1000000) val = 1000000;
        sett.insert(MP(val, i));
    }

    for(i=2;i<=m;i++)
    {
        II = (*(sett.begin()));
        temp = II.second;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        sett.erase(sett.begin());

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        cnt[temp]++;

        if(val > 1000000) val = 1000000;
        sett.insert(MP(val, temp));
    }

    for(i=1;i<=n;i++)
    {
        if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    }

    return 1;

}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;
    Long inf = 2;
    for(i=1;i<=12;i++) inf *= 10;

    cin>>n>>m;

    for(i=1;i<=n;i++) scanf("%lld", &ar[i]);
    for(i=1;i<=n;i++) scanf("%lld", &pr[i]);

    ans = BS(0, inf, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


//Bismillahir Rahmanir Rahim
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 200000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

set<pair<double, int> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

Long check(Long curr, Long n, Long m)
{
    int i,temp;
    pair<double, int> II;
    double val;

    sett.clear();
    for(i=1; i<=n; i++) cnt[i] = 0;

    for(i=1; i<=n; i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val <= m+2) sett.insert(MP(val, i));
    }

    for(i=2; i<=m && !sett.empty(); i++)
    {
        II = (*(sett.begin()));
        temp = II.second;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        sett.erase(sett.begin());

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        if(val <= m+2) sett.insert(MP(val, temp));
        cnt[temp]++;
    }

    for(i=1; i<=n; i++) if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    return 1;
}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;

    cin>>n>>m;

    for(i=1; i<=n; i++) scanf("%lld", &ar[i]);
    for(i=1; i<=n; i++) scanf("%lld", &pr[i]);

    ans = BS(0, 2000000000000LL, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


//Bismillahir Rahmanir Rahim
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#define double long double
#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 1000000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

set<pair<double, Long> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

Long check(Long curr, Long n, Long m)
{
    Long i,j,k,l,temp;
    pair<double, Long> II;
    double val;

    sett.clear();
    for(i=1; i<=n; i++) cnt[i] = 0;

    for(i=1; i<=n; i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val <= m+2) sett.insert(MP(val, i));
    }

    for(i=2; i<=m && !sett.empty(); i++)
    {
        II = (*(sett.begin()));
        temp = II.second;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        sett.erase(sett.begin());

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        if(val <= m+2) sett.insert(MP(val, temp));
        cnt[temp]++;
    }

    for(i=1; i<=n; i++)
    {
        if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    }

    return 1;

}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;

    cin>>n>>m;

    for(i=1; i<=n; i++) scanf("%lld", &ar[i]);
    for(i=1; i<=n; i++) scanf("%lld", &pr[i]);

    ans = BS(0, 2000000000000LL, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


//Bismillahir Rahmanir Rahim
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 200000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

priority_queue <pair<double, int> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

Long check(Long curr, Long n, Long m)
{
    int i, temp;
    pair<double, int> II;
    double val;

    while(!sett.empty()) sett.pop();
    for(i=1; i<=n; i++) cnt[i] = 0;

    for(i=1; i<=n; i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val <= m+2) sett.push(MP(-val, i));
    }

    for(i=2; i<=m && !sett.empty(); i++)
    {
        II = sett.top();
        sett.pop();

        temp = II.second;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        cnt[temp]++;
        if(val <= m+2) sett.push(MP(-val, temp));
    }

    for(i=1; i<=n; i++) if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    return 1;
}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;
    Long inf = 2;
    for(i=1; i<=12; i++) inf *= 10;

    cin>>n>>m;

    for(i=1; i<=n; i++) scanf("%lld", &ar[i]);
    for(i=1; i<=n; i++) scanf("%lld", &pr[i]);

    ans = BS(0, inf, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


//Bismillahir Rahmanir Rahim
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

#define double long double
#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 1000000
#define MOD 1000000007
#define INF 0x3f3f3f3f

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

set<pair<double, Long> > sett;
Long ar[MAX+9], pr[MAX+9], cnt[MAX+9];

Long check(Long curr, Long n, Long m)
{
    Long i,j,k,l,temp;
    pair<double, Long> II;
    double val;

    sett.clear();
    for(i=1; i<=n; i++) cnt[i] = 0;

    for(i=1; i<=n; i++)
    {
        val = (ar[i] * 1.0) / (pr[i] * 1.0);
        if(val <= m+2) sett.insert(MP(val, i));
    }

    for(i=2; i<=m && !sett.empty(); i++)
    {
        II = (*(sett.begin()));
        temp = II.second;

        if(ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr < 0) return 0;
        if(ar[temp] - (i-2) * pr[temp] + (cnt[temp]) * curr < 0) return 0;

        sett.erase(sett.begin());

        val = ar[temp] - (i-1) * pr[temp] + (1 + cnt[temp]) * curr;
        val /= pr[temp];
        val += i - 1;

        if(val <= m+2) sett.insert(MP(val, temp));
        cnt[temp]++;
    }

    for(i=1; i<=n; i++)
    {
        if(ar[i] - pr[i] * (m-1) + cnt[i] * curr < 0) return 0;
    }

    return 1;

}

Long BS(Long l, Long r, Long n, Long m)
{
    if(abs(r-l) <= 1)
    {
        if(check(l,n,m)) return l;
        return r;
    }

    Long mid = l + r;
    mid /= 2;

    if(check(mid, n, m)) return BS(l, mid, n, m);
    return BS(mid, r, n, m);
}

int main()
{
    Long i,j,k,n,m,ans;

    cin>>n>>m;

    for(i=1; i<=n; i++) scanf("%lld", &ar[i]);
    for(i=1; i<=n; i++) scanf("%lld", &pr[i]);

    ans = BS(0, 1000000000000LL, n, m);
    if(check(ans, n, m) == 0) ans = -1;

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N];
int n,k,b[N];
struct vv{
    ll p;
    int id;
    ll a1;
    int b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(1ll*temp.b1*1ll*(i-1)>temp.a1)   return false;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/(1ll*temp.b1),i,temp.a1,temp.b1});
    }
    return true;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/(1ll*b[i]),i,a[i],b[i]});
    }
    ll l=0,r=2e12,ans=2e12;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==2e12?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,k,a[N],b[N];
struct vv{
    ll p,id,a1,b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(temp.b1*(i-1)>temp.a1)   return false;
        //if(x==6)    cout<<temp.b1<<' '<<i<<' '<<temp.a1<<endl;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/temp.b1,i,temp.a1,temp.b1});
    }
    while(q2.size())
    {
        auto temp=q2.top();
        q2.pop();
        if(temp.b1*(k-1)>temp.a1)   return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%lld",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/b[i],i,a[i],b[i]});
    }
    ll l=0,r=1e15,ans=1e15;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==1e18?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N];
int n,k,b[N];
struct vv{
    ll p;
    int id;
    ll a1;
    int b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(1ll*temp.b1*1ll*(i-1)>temp.a1)   return false;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/(1ll*temp.b1),i,temp.a1,temp.b1});
    }
    while(q2.size())
    {
        auto temp=q2.top();
        q2.pop();
        if(1ll*temp.b1*(k-1)>temp.a1)   return false;
    }
    return true;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/(1ll*b[i]),i,a[i],b[i]});
    }
    //while(q.size())
    //{
    //    auto temp=q.top();
    //    q.pop();
    //    cout<<temp.p<<' '<<temp.id<<' '<<temp.a1<<' '<<temp.b1<<' '<<endl;
    //}
    ll l=0,r=1e12,ans=1e12;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==1e12?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,k,a[N],b[N];
struct vv{
    ll p,id,a1,b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(temp.b1*(i-1)>temp.a1)   return false;
        //if(x==6)    cout<<temp.b1<<' '<<i<<' '<<temp.a1<<endl;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/temp.b1,i,temp.a1,temp.b1});
    }
    while(q2.size())
    {
        auto temp=q2.top();
        q2.pop();
        if(temp.b1*(k-1)>temp.a1)   return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%lld",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/b[i],i,a[i],b[i]});
    }
    ll l=0,r=1e14,ans=1e14;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==1e18?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,k,a[N],b[N];
struct vv{
    ll p,id,a1,b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(temp.b1*(i-1)>temp.a1)   return false;
        //if(x==6)    cout<<temp.b1<<' '<<i<<' '<<temp.a1<<endl;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/temp.b1,i,temp.a1,temp.b1});
    }
    while(q2.size())
    {
        auto temp=q2.top();
        q2.pop();
        if(temp.b1*(k-1)>temp.a1)   return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%lld",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/b[i],i,a[i],b[i]});
    }
    ll l=0,r=1e16,ans=1e18;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==1e18?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,k,a[N],b[N];
struct vv{
    ll p,id,a1,b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(temp.b1*(i-1)>temp.a1)   return false;
        //if(x==6)    cout<<temp.b1<<' '<<i<<' '<<temp.a1<<endl;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/temp.b1,i,temp.a1,temp.b1});
    }
    while(q2.size())
    {
        auto temp=q2.top();
        q2.pop();
        if(temp.b1*(k-1)>temp.a1)   return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%lld",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/b[i],i,a[i],b[i]});
    }
    ll l=0,r=1e14,ans=1e14;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==1e14?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,k,a[N],b[N];
struct vv{
    ll p,id,a1,b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(temp.b1*(i-1)>temp.a1)   return false;
        //if(x==6)    cout<<temp.b1<<' '<<i<<' '<<temp.a1<<endl;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/temp.b1,i,temp.a1,temp.b1});
    }
    while(q2.size())
    {
        auto temp=q2.top();
        q2.pop();
        if(temp.b1*(k-1)>temp.a1)   return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%lld",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/b[i],i,a[i],b[i]});
    }
    ll l=0,r=1e18,ans=1e18;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==1e18?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N];
int n,k,b[N];
struct vv{
ll p;
int id;
ll a1;
int b1;
friend bool operator<(struct vv x,struct vv y)
{
if(x.p==y.p) return x.id<y.id;
else return x.p>y.p;
}
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
q2=q;
for(int i=1;i<=k;i++)
{
auto temp=q2.top();
if(1ll*temp.b1*1ll*(i-1)>temp.a1) return false;
temp.a1+=x;
q2.pop();
q2.push({temp.a1/(1ll*temp.b1),i,temp.a1,temp.b1});
}
return true;
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
for(int i=1;i<=n;i++)
{
q.push({a[i]/(1ll*b[i]),i,a[i],b[i]});
}
ll l=0,r=2e12,ans=2e12;
while(l<=r)
{
ll mid=(l+r)>>1;
if(ck(mid))
{
r=mid-1;
ans=min(ans,mid);
}
else l=mid+1;
}
ans==2e12?puts("-1"):printf("%lld\n",ans);
return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,k,a[N],b[N];
struct vv{
    ll p,id,a1,b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(temp.b1*(i-1)>temp.a1)   return false;
        //if(x==6)    cout<<temp.b1<<' '<<i<<' '<<temp.a1<<endl;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/temp.b1,i,temp.a1,temp.b1});
    }
    while(q2.size())
    {
        auto temp=q2.top();
        q2.pop();
        if(temp.b1*(k-1)>temp.a1)   return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%lld",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/b[i],i,a[i],b[i]});
    }
    ll l=0,r=1e13,ans=1e13;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==1e13?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,k,a[N],b[N];
struct vv{
    ll p,id,a1,b1;
    friend bool operator<(struct vv x,struct vv y)
    {
        if(x.p==y.p)  return x.id<y.id;
        else        return x.p>y.p;
    }
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
    q2=q;
    for(int i=1;i<=k;i++)
    {
        auto temp=q2.top();
        if(temp.b1*(i-1)>temp.a1)   return false;
        temp.a1+=x;
        q2.pop();
        q2.push({temp.a1/temp.b1,i,temp.a1,temp.b1});
    }
    while(q2.size())
    {
        auto temp=q2.top();
        q2.pop();
        if(temp.b1*(k-1)>temp.a1)   return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)   scanf("%lld",&b[i]);
    for(int i=1;i<=n;i++)
    {
        q.push({a[i]/b[i],i,a[i],b[i]});
    }
    ll l=0,r=1e12,ans=1e12;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(ck(mid))
        {
            r=mid-1;
            ans=min(ans,mid);
        }
        else    l=mid+1;
    }
    ans==1e12?puts("-1"):printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,k,a[N],b[N];
struct vv{
ll p,id,a1,b1;
friend bool operator<(struct vv x,struct vv y)
{
if(x.p==y.p) return x.id<y.id;
else return x.p>y.p;
}
};
priority_queue<vv>q;
priority_queue<vv>q2;
bool ck(ll x)
{
q2=q;
for(int i=1;i<=k;i++)
{
auto temp=q2.top();
if(temp.b1*(i-1)>temp.a1) return false;
//if(x==6) cout<<temp.b1<<' '<<i<<' '<<temp.a1<<endl;
temp.a1+=x;
q2.pop();
q2.push({temp.a1/temp.b1,i,temp.a1,temp.b1});
}
while(q2.size())
{
auto temp=q2.top();
q2.pop();
if(temp.b1*(k-1)>temp.a1) return false;
}
return true;
}
int main()
{
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
for(int i=1;i<=n;i++)
{
q.push({a[i]/b[i],i,a[i],b[i]});
}
ll l=0,r=1e18,ans=1e18;
while(l<=r)
{
ll mid=(l+r)>>1;
if(ck(mid))
{
r=mid-1;
ans=min(ans,mid);
}
else l=mid+1;
}
ans==1e18?puts("-1"):printf("%lld\n",ans);
return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<double, int>a, pair<double, int>b)
    {
        if(abs(a.first - b.first) <= 1e-9)
            return v[a.second].y > v[b.second].y;
        return a.first - b.first > 1e-9;
    }
};
priority_queue<pair<double, int>, vector<pair<double, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    long long intt = 0;
    for(int i = 1; i <= n; ++i)
    {
        long long ch = max(0LL, v[i].y * (k - 1) - v[i].x);
        if(m == 0)
        {
            if(ch)
                return 0;
        }
        else
            intt += (ch / m) + (ch % m > 0);
    }
    if(intt > k)
        return 0;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        if(1LL * v[i].y * (k - 1) <= tru[i]);
        else
            q.push({(0.000000 + tru[i]) / (0.00000 + v[i].y), i});
    for(int i = 1; i <= k; ++i)
    {
        if(q.empty())
            return 1;
        pair<double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        if((k - 1) * v[z.second].y > tru[z.second])
            q.push({(0.0000 + tru[z.second]) / (0.00000 + v[z.second].y), z.second});
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<45);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<long double, int>a, pair<long double, int>b)
    {
        if(abs(a.first - b.first) <= 1e-9)
            return v[a.second].y > v[b.second].y;
        return a.first - b.first > 1e-9;
    }
};
priority_queue<pair<long double, int>, vector<pair<long double, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    long long intt = 0;
    for(int i = 1; i <= n; ++i)
    {
        long long ch = max(0LL, v[i].y * (k - 1) - v[i].x);
        if(m == 0)
        {
            if(ch)
                return 0;
        }
        else
            intt += (ch / m) + (ch % m > 0);
    }
    if(intt > k)
        return 0;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        if(1LL * v[i].y * (k - 1) <= tru[i]);
        else
            q.push({(0.000000 + tru[i]) / (0.00000 + v[i].y), i});
    for(int i = 1; i <= k; ++i)
    {
        if(q.empty())
            return 1;
        pair<long double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        if((k - 1) * v[z.second].y > tru[z.second])
            q.push({(0.0000 + tru[z.second]) / (0.00000 + v[z.second].y), z.second});
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<45);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
struct cmp
{
    bool operator()(pair<long long, int>a, pair<long long, int>b)
    {
        return a.first > b.first;
    }
};
priority_queue<pair<long long, int>, vector<pair<long long, int> >, cmp>q;
long long tru[200002];
int lst[200002];
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        q.push({tru[i] / v[i].y, i});
    for(int i = 1; i <= k; ++i)
    {
        pair<long long, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m - 1LL * (i - 1 - lst[z.second]) * v[z.second].y;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        q.push({tru[z.second] / v[z.second].y, z.second});
    }
    while(!q.empty())
    {
        pair<long long, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (k - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<50);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<double, int>a, pair<double, int>b)
    {
        if(a.first == b.first)
            return v[a.second].y > v[b.second].y;
        return a.first > b.first;
    }
};
priority_queue<pair<double, int>, vector<pair<double, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        q.push({(0.000000 + tru[i]) / (0.00000 + v[i].y), i});
    for(int i = 1; i <= k; ++i)
    {
        pair<double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m - 1LL * (i - 1 - lst[z.second]) * v[z.second].y;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        q.push({(0.0000 + tru[z.second]) / (0.00000 + v[z.second].y), z.second});
    }
    while(!q.empty())
    {
        pair<double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (k - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<60);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<long double, int>a, pair<long double, int>b)
    {
        if(abs(a.first - b.first) <= 1e-9)
            return v[a.second].y > v[b.second].y;
        return a.first - b.first > 1e-9;
    }
};
priority_queue<pair<long double, int>, vector<pair<long double, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    long long intt = 0;
    for(int i = 1; i <= n; ++i)
    {
        long long ch = max(0LL, v[i].y * (k - 1) - v[i].x);
        if(m == 0)
        {
            if(ch)
                return 0;
        }
        else
            intt += (ch / m) + (ch % m > 0);
    }
    if(intt > k)
        return 0;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        if(1LL * v[i].y * (k - 1) <= tru[i]);
        else
            q.push({(0.000000 + tru[i]) / (0.00000 + v[i].y), i});
    for(int i = 1; i <= k; ++i)
    {
        if(q.empty())
            return 1;
        pair<long double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        if((k - i) * v[z.second].y > tru[z.second])
            q.push({(0.0000 + tru[z.second]) / (0.00000 + v[z.second].y), z.second});
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<45);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<long double, int>a, pair<long double, int>b)
    {
        if(abs(a.first - b.first) <= 1e-9)
            return v[a.second].y > v[b.second].y;
        return a.first - b.first > 1e-9;
    }
};
priority_queue<pair<long double, int>, vector<pair<long double, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    long long intt = 0;
    for(int i = 1; i <= n; ++i)
    {
        long long ch = max(0LL, v[i].y * (k - 1) - v[i].x);
        if(m == 0)
        {
            if(ch)
                return 0;
        }
        else
            intt += (ch / m) + (ch % m > 0);
    }
    if(intt > k)
        return 0;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        if(1LL * v[i].y * (k - 1) <= tru[i]);
        else
            q.push({(0.000000 + tru[i]) / (0.00000 + v[i].y), i});
    for(int i = 1; i <= k; ++i)
    {
        if(q.empty())
            return 1;
        pair<long double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m - 1LL * (i - 1 - lst[z.second]) * v[z.second].y;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        if((k - i) * v[z.second].y > tru[z.second])
            q.push({(0.0000 + tru[z.second]) / (0.00000 + v[z.second].y), z.second});
    }
    while(!q.empty())
    {
        pair<long double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (k - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<45);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<long long, int>a, pair<long long, int>b)
    {
        if(a.first == b.first)
        {
            double rapp = (0.0000 + tru[a.second]) / (0.0000 + v[a.second].y);
            double rapp2 = (0.0000 + tru[b.second]) / (0.0000 + v[b.second].y);
            if(rapp == rapp2)
                return v[a.second].y > v[b.second].y;
            return rapp > rapp2;
        }
        return a.first > b.first;
    }
};
priority_queue<pair<long long, int>, vector<pair<long long, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        q.push({tru[i] / v[i].y, i});
    for(int i = 1; i <= k; ++i)
    {
        pair<long long, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m - 1LL * (i - 1 - lst[z.second]) * v[z.second].y;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        q.push({tru[z.second] / v[z.second].y, z.second});
    }
    while(!q.empty())
    {
        pair<long long, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (k - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<50);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<double, int>a, pair<double, int>b)
    {
        if(a.first == b.first)
            return v[a.second].y > v[b.second].y;
        return a.first > b.first;
    }
};
priority_queue<pair<double, int>, vector<pair<double, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        if(1LL * v[i].y * (k - 1) <= tru[i]);
        else
            q.push({(0.000000 + tru[i]) / (0.00000 + v[i].y), i});
    for(int i = 1; i <= k; ++i)
    {
        if(q.empty())
            return 1;
        pair<double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m - 1LL * (i - 1 - lst[z.second]) * v[z.second].y;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        if((k - i) * v[z.second].y > tru[z.second])
            q.push({(0.0000 + tru[z.second]) / (0.00000 + v[z.second].y), z.second});
    }
    while(!q.empty())
    {
        pair<double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (k - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<60);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<double, int>a, pair<double, int>b)
    {
        if(abs(a.first - b.first) <= 1e-9)
            return v[a.second].y > v[b.second].y;
        return a.first - b.first > 1e-9;
    }
};
priority_queue<pair<double, int>, vector<pair<double, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    long long intt = 0;
    for(int i = 1; i <= n; ++i)
    {
        long long ch = max(0LL, v[i].y * (k - 1) - v[i].x);
        if(m == 0)
        {
            if(ch)
                return 0;
        }
        else
            intt += (ch / m) + (ch % m > 0);
    }
    if(intt > k)
        return 0;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        if(1LL * v[i].y * (k - 1) <= tru[i]);
        else
            q.push({(0.000000 + tru[i]) / (0.00000 + v[i].y), i});
    for(int i = 1; i <= k; ++i)
    {
        if(q.empty())
            return 1;
        pair<double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        if((k - 1) * v[z.second].y > tru[z.second])
            q.push({(0.0000 + tru[z.second]) / (0.00000 + v[z.second].y), z.second});
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<42);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<long double, int>a, pair<long double, int>b)
    {
        if(abs(a.first - b.first) <= 1e-9)
            return v[a.second].y > v[b.second].y;
        return a.first - b.first > 1e-9;
    }
};
priority_queue<pair<long double, int>, vector<pair<long double, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        if(1LL * v[i].y * (k - 1) <= tru[i]);
        else
            q.push({(0.000000 + tru[i]) / (0.00000 + v[i].y), i});
    for(int i = 1; i <= k; ++i)
    {
        if(q.empty())
            return 1;
        pair<long double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m - 1LL * (i - 1 - lst[z.second]) * v[z.second].y;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        if((k - i) * v[z.second].y > tru[z.second])
            q.push({(0.0000 + tru[z.second]) / (0.00000 + v[z.second].y), z.second});
    }
    while(!q.empty())
    {
        pair<long double, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (k - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<45);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
	long long a = rng();
    return a;
}
int n, k;
struct el
{
    long long x, y;
};
el v[200002];
long long tru[200002];
int lst[200002];
struct cmp
{
    bool operator()(pair<long long, int>a, pair<long long, int>b)
    {
        if(a.first == b.first)
        {
            double rapp = (0.0000 + tru[a.second]) / (0.0000 + v[a.second].y);
            double rapp2 = (0.0000 + tru[b.second]) / (0.0000 + v[b.second].y);
            return rapp > rapp2;
        }
        return a.first > b.first;
    }
};
priority_queue<pair<long long, int>, vector<pair<long long, int> >, cmp>q;
bool check(long long m)
{
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; ++i)
        tru[i] = v[i].x;
    memset(lst, 0, sizeof(lst));
    for(int i = 1; i <= n; ++i)
        q.push({tru[i] / v[i].y, i});
    for(int i = 1; i <= k; ++i)
    {
        pair<long long, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (i - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
        long long aa = tru[z.second] + m - 1LL * (i - 1 - lst[z.second]) * v[z.second].y;
        lst[z.second] = i - 1;
        tru[z.second] = aa;
        q.push({tru[z.second] / v[z.second].y, z.second});
    }
    while(!q.empty())
    {
        pair<long long, int> z = q.top();
        q.pop();
        if(tru[z.second] - 1LL * (k - 1 - lst[z.second]) * v[z.second].y < 0)
            return 0;
    }
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].x;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].y;
    long long st = 0;
    long long dr = (1LL<<50);
    long long ans = -1;
    while(st <= dr)
    {
        long long mid = (st + dr) / 2;
        if(check(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    ll cn;
    node(ll x,ll y){s=x,c=y;cn=s/c;}
    bool operator<(const node &b)const
    {
        return cn>b.cn;
    }
};
ll a[N],b[N];
priority_queue<node>qq;
bool judge(ll x)
{
    priority_queue<node>q(qq);
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        if(q.empty())return true;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
//            if(tmp.s<0)
//            {
//                cout<<"溢出"<<endl;
//            }
            tmp.cn=tmp.s/tmp.c;
            if(tmp.cn<i-1)return false;
            if(tmp.cn>=k-1)continue;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.cn<k-1)return false;
         if(tmp.cn>=k-1)return 1;
    }
    return true;
}
void init()
{
     for(int i=0;i<n;i++)
    {
        qq.push(node(a[i],b[i]));
    }
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%I64d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%I64d",&b[i]);
    }
    init();
    ll l=0,r=1e13;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e13)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    ll cn;
    node(int x,int y){s=x,c=y;cn=s/c;}
    bool operator<(const node &b)const
    {
        return cn>b.cn;
    }
};
int a[N],b[N];
priority_queue<node>qq;
bool judge(ll x)
{
    priority_queue<node>q(qq);
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        if(q.empty())return true;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            tmp.cn=tmp.s/tmp.c;
            if(tmp.cn<i-1)return false;
            if(tmp.cn>=k-1)continue;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.cn<k-1)return false;
         if(tmp.cn>=k-1)return 1;
    }
    return true;
}
void init()
{
     for(int i=0;i<n;i++)
    {
        qq.push(node(a[i],b[i]));
    }
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    init();
    ll l=0,r=1e13;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e13)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
    //    cout<<"SSS"<<a[i]<<" "<<b[i]<<endl;
        q.push(node(a[i],b[i]));
    }
//    while(!q.empty())
//    {
//          node tmp=q.top();q.pop();
//          cout<<tmp.s<<" "<<tmp.c<<endl;
//    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        node tmp=q.top();q.pop();
       // cout<<tmp.s<<" "<<tmp.c<<endl;
        if(tmp.s/tmp.c<i-2)
        {
          //  cout<<"###"<<tmp.s<<" "<<tmp.c<<" "<<i<<endl;
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            q.push(tmp);
        }
    }
//    cout<<q.size()<<endl;
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=1,r=1e9;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e9)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node &b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
        q.push(node(a[i],b[i]));
    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
         if(tmp.s/tmp.c>=k-1)return true;
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e12;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e12)
    {
        printf("-1\n");
    }
    else
    {
        printf("%I64d\n",l);
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    ll cn;
    node(int x,int y){s=x,c=y;cn=s/c;}
    bool operator<(const node &b)const
    {
        return cn>b.cn;
    }
};
int a[N],b[N];
priority_queue<node>qq;
bool judge(ll x)
{
    priority_queue<node>q(qq);
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        if(q.empty())return true;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            tmp.cn=tmp.s/tmp.c;
            if(tmp.cn<i-1)return false;
            if(tmp.cn>=k-1)continue;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.cn<k-1)return false;
         if(tmp.cn>=k-1)return 1;
    }
    return true;
}
void init()
{
     for(int i=0;i<n;i++)
    {
        qq.push(node(a[i],b[i]));
    }
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    init();
    ll l=0,r=1e12;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e12)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
    //    cout<<"SSS"<<a[i]<<" "<<b[i]<<endl;
        q.push(node(a[i],b[i]));
    }
//    while(!q.empty())
//    {
//          node tmp=q.top();q.pop();
//          cout<<tmp.s<<" "<<tmp.c<<endl;
//    }
    for(int i=1;i<=k;i++)
    {
        node tmp=q.top();q.pop();
       // cout<<tmp.s<<" "<<tmp.c<<endl;
        if(tmp.s/tmp.c<i-1)
        {
          //  cout<<"###"<<tmp.s<<" "<<tmp.c<<" "<<i<<endl;
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i)return false;
            q.push(tmp);
        }
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(5);
    ll l=1,r=1e18;
    while(l<=r)
    {
        ll m=l+r>>1;
       // cout<<l<<" "<<r<<" "<<m<<"&&&"<<judge(m)<<endl;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e18)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
        //cout<<r<<" "<<l<<endl;
        //cout<<r<<" "<<l-1<<" "<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
    //    cout<<"SSS"<<a[i]<<" "<<b[i]<<endl;
        q.push(node(a[i],b[i]));
    }
//    while(!q.empty())
//    {
//          node tmp=q.top();q.pop();
//          cout<<tmp.s<<" "<<tmp.c<<endl;
//    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        if(q.empty())return true;
        node tmp=q.top();q.pop();
       // cout<<tmp.s<<" "<<tmp.c<<endl;
        if(tmp.s/tmp.c<i-2)
        {
          //  cout<<"###"<<tmp.s<<" "<<tmp.c<<" "<<i<<endl;
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            if(tmp.s/tmp.c>=k-1)continue;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
         if(tmp.s/tmp.c>=k-1)return 1;
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e13;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e13)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
    //    cout<<"SSS"<<a[i]<<" "<<b[i]<<endl;
        q.push(node(a[i],b[i]));
    }
//    while(!q.empty())
//    {
//          node tmp=q.top();q.pop();
//          cout<<tmp.s<<" "<<tmp.c<<endl;
//    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        node tmp=q.top();q.pop();
       // cout<<tmp.s<<" "<<tmp.c<<endl;
        if(tmp.s/tmp.c<i-2)
        {
          //  cout<<"###"<<tmp.s<<" "<<tmp.c<<" "<<i<<endl;
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
         if(tmp.s/tmp.c>=k-1)return 1;
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e13;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e13)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node &b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
        q.push(node(a[i],b[i]));
    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        if(q.empty())return true;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            if(tmp.s/tmp.c>=k-1)continue;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
         if(tmp.s/tmp.c>=k-1)return 1;
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e12;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e12)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
    //    cout<<"SSS"<<a[i]<<" "<<b[i]<<endl;
        q.push(node(a[i],b[i]));
    }
//    while(!q.empty())
//    {
//          node tmp=q.top();q.pop();
//          cout<<tmp.s<<" "<<tmp.c<<endl;
//    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        node tmp=q.top();q.pop();
       // cout<<tmp.s<<" "<<tmp.c<<endl;
        if(tmp.s/tmp.c<i-2)
        {
          //  cout<<"###"<<tmp.s<<" "<<tmp.c<<" "<<i<<endl;
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            q.push(tmp);
        }
    }
//    cout<<q.size()<<endl;
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e9;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e9)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    ll cn;
    node(int x,int y){s=x,c=y;cn=s/c;}
    bool operator<(const node &b)const
    {
        return cn>b.cn;
    }
};
int a[N],b[N];
priority_queue<node>qq;
bool judge(ll x)
{
    priority_queue<node>q(qq);
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        if(q.empty())return true;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s<0)
            {
                cout<<"溢出"<<endl;
            }
            tmp.cn=tmp.s/tmp.c;
            if(tmp.cn<i-1)return false;
            if(tmp.cn>=k-1)continue;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.cn<k-1)return false;
         if(tmp.cn>=k-1)return 1;
    }
    return true;
}
void init()
{
     for(int i=0;i<n;i++)
    {
        qq.push(node(a[i],b[i]));
    }
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    init();
    ll l=0,r=1e13;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e13)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node &b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
        q.push(node(a[i],b[i]));
    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        if(q.empty())return   1;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            if(tmp.s/tmp.c>=k-1)continue;
            q.push(tmp);
        }
    }
    if(q.size())return false;
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e13;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(l>=1e13)
    {
        printf("-1\n");
    }
    else
    {
        printf("%I64d\n",l);
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node &b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
priority_queue<node>qq;
bool judge(ll x)
{
    priority_queue<node>q(qq);
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        if(q.empty())return true;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            if(tmp.s/tmp.c>=k-1)continue;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
         if(tmp.s/tmp.c>=k-1)return 1;
    }
    return true;
}
void init()
{
     for(int i=0;i<n;i++)
    {
        qq.push(node(a[i],b[i]));
    }
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    init();
   // judge(1);
    ll l=0,r=1e12;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e12)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node &b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
        q.push(node(a[i],b[i]));
    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
         if(tmp.s/tmp.c>=k-1)return true;
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e12;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e13)
    {
        printf("-1\n");
    }
    else
    {
        printf("%I64d\n",l);
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
    //    cout<<"SSS"<<a[i]<<" "<<b[i]<<endl;
        q.push(node(a[i],b[i]));
    }
//    while(!q.empty())
//    {
//          node tmp=q.top();q.pop();
//          cout<<tmp.s<<" "<<tmp.c<<endl;
//    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        node tmp=q.top();q.pop();
       // cout<<tmp.s<<" "<<tmp.c<<endl;
        if(tmp.s/tmp.c<i-2)
        {
          //  cout<<"###"<<tmp.s<<" "<<tmp.c<<" "<<i<<endl;
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            q.push(tmp);
        }
    }
    while(!q.empty())
    {
         node tmp=q.top();q.pop();
         if(tmp.s/tmp.c<k-1)return false;
         if(tmp.s/tmp.c>=k-1)return 1;
    }
    return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e9;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e9)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<l<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define P pair<int,int>
using namespace std;
const int N=2e5+5;
int n,k;
struct node
{
    ll s,c;
    node(int x,int y){s=x,c=y;}
    bool operator<(const node &b)const
    {
        return s/c>b.s/b.c;
    }
};
int a[N],b[N];
bool judge(ll x)
{
    priority_queue<node>q;
    for(int i=0;i<n;i++)
    {
        q.push(node(a[i],b[i]));
    }
    for(int i=1;i<=k;i++)
    {
        if(i==1)continue;
        node tmp=q.top();q.pop();
        if(tmp.s/tmp.c<i-2)
        {
            return false;
        }
        else
        {
            tmp.s+=x;
            if(tmp.s/tmp.c<i-1)return false;
            if(tmp.s/tmp.c>=k-1)continue;
            q.push(tmp);
        }
    }
    if(q.size())return false;
    else return true;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
   // judge(1);
    ll l=0,r=1e12;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m))r=m-1;
        else l=m+1;
    }
    if(r>=1e12)
    {
        printf("-1\n");
    }
    else
    {
        printf("%I64d\n",l);
    }
    return 0;
}


#define _rep(i,a,b) for(int i=a;i<=b;++i)
#include <iostream>
#include <vector>
#include <queue>
#include <cassert>
#include <algorithm>
typedef unsigned long long LL;
using namespace std;
const int MAXN = 2e5;
LL a[MAXN+4],b[MAXN+4];
int n,k;
struct node{
  LL a,b;
  node(LL a=0,LL b=0):a(a),b(b) {}
  bool operator<(const node &rhs) const {
    return a*rhs.b > rhs.a*b;
  }
};
struct heap{
  node a[MAXN+4];
  int r = 0;
  void push(node x) {
    a[r++] = x;
    push_heap(a,a+r);
  }
  node top() {
    return a[0];
  }
  void pop() {
    assert( !empty() );
    pop_heap(a,a+r--);
  }
  bool empty() {
    return r == 0;
  }
}Q;

bool check(int mid) {
  heap bq = Q;
  LL t = 1;
  while( t < (LL)k ) {
    //!!!
    if( bq.empty() ) return true;
    auto x = bq.top(); bq.pop();
    if( !bq.empty() ) {
      auto y = bq.top();
      if( y.a < y.b*t ) return false;
    }
    x.a += mid;
    if( x.a < x.b*t ) return false;
    if( x.b*k > x.a ) bq.push( x );
    ++t;
  }
  return true;
}

int main() {
//  freopen("in","r",stdin);
//  ios::sync_with_stdio(false);
//  cin.tie(0)
  cin >> n >> k;
  LL r = 0;
  _rep(i,1,n) cin >> a[i];
  _rep(i,1,n) {
    cin >> b[i];
    if( b[i]*k > a[i] )
      Q.push( node(a[i],b[i]) );
    r = max( (LL)r , b[i]*k );
  }
  LL l = 0 , mid , ans = -1;
  while( l <= r ) {
    mid = l + ((r-l)>>1);
    if( check(mid) )
      ans = mid , r = mid-1;
    else l = mid+1;
  }
  if( ans == LL(-1) )
      cout << "-1\n";
  else cout << ans << '\n';
  return 0;
}


#define _for(i,a,b) for(int i=a;i< b;++i)
#define _rep(i,a,b) for(int i=a;i<=b;++i)
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
typedef long long LL;
using namespace std;
const int MAXN = 2e5;
LL n,k,a[MAXN+4],b[MAXN+4],cur[MAXN+4];
vector<LL> ve[MAXN+4];

void test(const vector<LL> &v) {
  cout << '\n';
  for(auto x:v) cout << x << ' ';
  cout << '\n';
  return;
}

bool check(LL mid) {
  _rep(i,1,k) ve[i].clear();
  _rep(i,1,n) {
    LL t = a[i]/b[i]+1;
    if( t < k ) {
      ve[t].push_back( i );
      cur[i] = a[i]%b[i];
    }
  }

  int it = 1;
  for(int t=1; t <= k; ++t) {
    while( it < k && ve[it].empty() ) ++it;
    if( it == k ) return true;
    if( it < t ) return false;
    int idx = ve[it].back();
    cur[idx] += mid;
    if( cur[idx] >= b[idx] ) {
      ve[it].pop_back();
      LL del = cur[idx] / b[idx];
      if( it+del < k ) {
        ve[it+del].push_back( idx );
        cur[idx] %= b[idx];
      }
    }
  }
  return true;
}

int main() {
//  freopen("in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  _rep(i,1,n) cin >> a[i];
  _rep(i,1,n) cin >> b[i];

  LL l = 0 , r = 10LL+2e12 , mid , ans = -1;
  while( l <= r ) {
    mid = l + ((r-l)>>1);
    if( check(mid) )
      ans = mid , r = mid - 1;
    else l = mid + 1;
  }
  cout << ans << '\n';
  return 0;
}