#include #include #include using namespace std; const int oo = int((1LL << 31) - 1); vector A, B; int N, M; class Compare { public: bool operator()(const int x, const int y) const { return A[x] < A[y]; } }; inline int CountDistinctValues(vector values) { sort(values.begin(), values.end()); values.erase(unique(values.begin(), values.end()), values.end()); return int(values.size()); } void Solve() { vector indices = vector(N); for (int i = 0; i < N; ++i) indices[i] = i; sort(indices.begin(), indices.end(), Compare()); int lowerBound = -oo; for (int i = 0; i < N; ++i) { int index = indices[i], best = oo; for (int j = 0; j < M; ++j) if (A[index] - B[j] > lowerBound) best = min(best, A[index] - B[j]); if (best == oo) best = lowerBound; lowerBound = A[index] = best; } } void Read() { cin >> N >> M; A = vector(N); for (int i = 0; i < N; ++i) cin >> A[i]; B = vector(M + 1); for (int i = 0; i < M; ++i) cin >> B[i]; B[M] = 0; ++M; } void Print() { cout << CountDistinctValues(A) << "\n"; for (int i = 0; i < N; ++i) cout << A[i] << " "; cout << "\n"; } int main() { Read(); Solve(); Print(); return 0; }