#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(v) begin(v), end(v)
using namespace std;
using ll = long long;
constexpr ll inf = 1e18;
template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }
int main() {
int N, K; cin >> N >> K;
vector<ll> C(N), V(N);
rep (i, N) cin >> C[i];
rep (i, N) cin >> V[i];
if (K == 1) {
ll ans = -inf;
rep (i, N) chmax(ans, V[i] - C[i]);
cout << ans << endl;
rep (i, N) cout << (V[i] - C[i] == ans);
cout << endl;
return 0;
}
vector<ll> CC(N + 1);
rep (i, N) CC[i + 1] = CC[i] + C[i];
vector dp(N + 1, vector<ll>(K + 1, -inf));
dp[0][0] = 0;
rep (i, N) rep (j, K + 1) {
chmax(dp[i + 1][j], dp[i][j]);
if (j == 0) chmax(dp[i + 1][j + 1], dp[i][j] + CC[i] + V[i]);
else if (j == K - 1) chmax(dp[i + 1][j + 1], dp[i][j] + V[i] - CC[i + 1]);
else chmax(dp[i + 1][j + 1], dp[i][j] + V[i]);
}
cout << dp[N][K] << endl;
vector<bool> ans(N);
vector<vector<bool>> used(N + 1, vector<bool>(K + 1, false));
used[N][K] = true;
rrep (i, N) rep (j, K + 1) {
if (used[i + 1][j] && dp[i + 1][j] == dp[i][j]) used[i][j] = true;
if (used[i + 1][j + 1]) {
if (j == 0) {
if (dp[i + 1][j + 1] == dp[i][j] + CC[i] + V[i]) used[i][j] = true, ans[i] = true;
}
else if (j == K - 1) {
if (dp[i + 1][j + 1] == dp[i][j] + V[i] - CC[i + 1]) used[i][j] = true, ans[i] = true;
}
else {
if (dp[i + 1][j + 1] == dp[i][j] + V[i]) used[i][j] = true, ans[i] = true;
}
}
}
rep (i, N) cout << ans[i];
cout << endl;
}