#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<int> a(n+1);
vector<int> b(n);
for(int i = 0; i < n+1; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for(int i = 0; i < n+1; i++){
int mx = 0;
vector<int> j = a;
j.erase(j.begin()+i);
for(int y = 0; y < n; y++){
mx = max(mx, max(0LL, j[y]-b[y]));
}
cout << mx << " ";
}cout << "\n";
return 0;
}
/*
observation -> sort it and pair by index, why is this good?
a1 a2 a3 a4 a5
b1 b2 b3 b4 b5
we know that each worker is better if we put a smaller chain after, so, after we sort both, b1, must be best to be at a1
why? since if b1 is paired with any other then it is more efficient that any other take that one
lets try to impl the n^2, just by sorting it
*/
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |