이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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> prfx(n+1);
//
// for(ll i = n-1; i >= 0; i--){
//
// prfx[i] = prfx[i+1] + (a[i+1] - a[i]);
// }
//
// // for(ll i = 0; i < n; i++)cout<<prfx[i]<<" ";
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]);
}
// 3
// 3 4 6 7
// 2 4 6
// 4
// 1 8 12 17 20
// 3 7 10 13
vector<ll> ans(n+1), ch(n);
for(ll i = n-1; i >= 0; i--){
ch[i] = max(0ll, a[i+1].f - b[i]);
ans[a[i].s] = max(mx, ch[i]);
}
ans[a[n].s] = mx;
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... |