Submission #787312

#TimeUsernameProblemLanguageResultExecution timeMemory
787312Sandarach151Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
231 ms20812 KiB
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; pair<long long, long long> arr[n+1]; long long ties[n]; for(long long i=0; i<=n; i++){ cin >> arr[i].first; arr[i].second = i; } for(long long i=0; i<n; i++){ cin >> ties[i]; } sort(arr, arr+n+1); sort(ties, ties+n); long long ans[n+1]; multiset<long long, greater<long long>> st; for(long long i=1; i<=n; i++){ st.insert(max((long long) 0, arr[i].first-ties[i-1])); ans[0]=*st.begin(); } for(long long taken = 1; taken<=n; taken++){ st.erase(st.find(max((long long) 0, arr[taken].first-ties[taken-1]))); st.insert(max((long long) 0, arr[taken-1].first-ties[taken-1])); ans[taken]=*st.begin(); } long long finans[n+1]; for(long long i=0; i<=n; i++){ finans[arr[i].second]=ans[i]; } for(long long i=0; i<=n; i++){ cout << finans[i] << ' '; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...