Submission #869225

#TimeUsernameProblemLanguageResultExecution timeMemory
869225goodspeed0208Just Long Neckties (JOI20_ho_t1)C++14
100 / 100
236 ms19536 KiB
#include<iostream> #include<vector> #include<algorithm> #include<utility> #include<set> using namespace std; //想10 實作10 signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<int, int> >a(n+1); vector<int> b(n); vector<int>ans(n); for (int i = 0 ; i < n+1 ; i++) { cin >> a[i].first; a[i].second = i; } for (auto &i : b) cin >> i; sort(a.begin(), a.end()); sort(b.begin(), b.end()); for (int i = 0 ; i < n ; i++) { ans[i] = max(a[i+1].first - b[i], 0); } vector<int>out(n+1); multiset<int>st; for (auto i : ans) st.insert(i); for (int i = 0 ; i < n+1 ; i++) { out[a[i].second] = *st.rbegin(); if (i == n) break; st.erase(st.find(ans[i])); ans[i] = max(a[i].first - b[i], 0); st.insert(ans[i]); } for (int i = 0 ; i < n+1 ; i++) { cout << out[i] << " "; } cout << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...