Submission #1133244

#TimeUsernameProblemLanguageResultExecution timeMemory
1133244UnforgettableplJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
70 ms11592 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<pair<int,int>> neckties(n+2); for(int i=1;i<=n+1;i++){cin>>neckties[i].first;neckties[i].second=i;} vector<int> people(n+1); for(int i=1;i<=n;i++)cin>>people[i]; vector<int> prefix(n+2); vector<int> suffix(n+2); sort(neckties.begin()+1,neckties.end()); sort(people.begin()+1,people.end()); for(int i=2;i<=n+1;i++) { prefix[i] = max(prefix[i-1],-(people[i-1]-neckties[i-1].first)); } for(int i=n;i;i--) { suffix[i] = max(suffix[i+1],-(people[i]-neckties[i+1].first)); } vector<int> ans(n+2); for(int i=1;i<=n+1;i++)ans[neckties[i].second]=max(prefix[i],suffix[i]); for(int i=1;i<=n+1;i++)cout<<ans[i]<<' '; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...