This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int M = 1e5 + 5, MOD = 1e9+7;
int a[M], b[M], ans[M], suf[M];
map<int, int> in;
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
srand(time(0));
int n;
cin >> n;
for (int i = 0; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
vector<int*> ind;
for (int i = 0; i <= n; i++) ind.push_back(&a[i]);
sort(ind.begin(), ind.end(), [](int*a,int*b){return *a<*b;});
for (int*i:ind) in[*i] = i-&a[0];
sort(b+1, b+n+1);
sort(a, a+n+1);
for (int i = n; i>=1; i--) {
suf[i] = max(suf[i+1], max(a[i]-b[i], 0ll));
}
int buff = a[0], k = 0;
for (int i = 0; i <= n; i++) {
ans[in[buff]] = max(suf[i+1], k);
k = max(k, max(buff-b[i+1], 0ll));
buff = a[i+1];
}
for (int i = 0; i <= n; i++) cout << ans[i] << ' '; cout << endl;
return 0;
}
/*
3
4 3 7 6
2 6 4
3
4 3 6 7
2 4 6
0 2 0 0
5
4 7 9 10 11 12
3 5 7 9 11
*/
Compilation message (stderr)
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:38:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
38 | for (int i = 0; i <= n; i++) cout << ans[i] << ' '; cout << endl;
| ^~~
ho_t1.cpp:38:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
38 | for (int i = 0; i <= n; i++) cout << ans[i] << ' '; cout << endl;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |