#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; const int INF = 1e9; int main(){ int n; cin >> n; vector x(n),y(n); rep(i,n) cin >> x[i]; rep(i,n) cin >> y[i]; vector

tapi; rep(i,n) { tapi.push_back({x[i],y[i]}); } sort(tapi.begin(),tapi.end()); vector res(n+2); res[0] = 0; res[1] = tapi[0].first; res[n+1] = tapi[0].second + tapi[0].first; for (int i = 2; i <= n; i++) { if (tapi[i-1].second < res[n+1] - res[1]) res[i] = res[n+1] - tapi[i-1].second; else res[i] = res[1]; } cout << res[n+1] << endl; for (auto e : res) { cout << e << endl; } return 0; }