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;
//Types
using ll = long long;
using db = double;
//Vectors
#define pb push_back
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(), vec.end()
//things
#define f first
#define s second
const int SMALLINF = 1e9 + 7;
const ll BIGINF = ((ll)1e18) + 7;
#define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
void solve(){
ll n;
cin>>n;
vector<pair<ll, ll> > a(n+1);
vector<ll> b(n);
for(ll i = 0; i < n+1; i++){
cin>>a[i].f;
a[i].s = i;
}
for(ll i = 0; i < n; i++){
cin>>b[i];
}
sort(all(a));
sort(all(b));
vector<ll> orig(n);
ll mx = 0;
for(ll i = n-1; i >= 0; i--){
orig[i] = max(0ll, a[i].f - b[i]);
mx = max(mx, orig[i]);
}
vector<ll> ans(n+1), ch(n);
ans[a[n].s] = mx;
for(ll i = n-1; i >= 0; i--){
ans[a[i].s] = max(mx, max(0ll, a[i+1].f - b[i]));
}
for(ll i = 0; i < n+1; i++)cout<<ans[i]<<" ";
}
int main(){
Speeed
ll t=1;
// cin>>t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |