Submission #937812

#TimeUsernameProblemLanguageResultExecution timeMemory
937812AndreyJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
75 ms15640 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,a; cin >> n; vector<long long> ans(n+1); vector<pair<long long,long long>> haha(n+1); vector<long long> bruh(n); for(long long i = 0; i <= n; i++) { cin >> a; haha[i] = {a,i}; } for(long long i = 0; i < n; i++) { cin >> bruh[i]; } sort(haha.begin(),haha.end()); sort(bruh.begin(),bruh.end()); vector<long long> pr(n+1); vector<long long> su(n+1); for(long long i = 1; i <= n; i++) { pr[i] = max(haha[i-1].first-bruh[i-1],0LL); pr[i] = max(pr[i],pr[i-1]); } for(long long i = n-1; i >= 0; i--) { su[i] = max(haha[i+1].first-bruh[i],0LL); su[i] = max(su[i],su[i+1]); } for(long long i = 0; i < n+1; i++) { ans[haha[i].second] = max(pr[i],su[i]); } for(long long i = 0; i < n+1; i++) { cout << ans[i] << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...