Submission #789477

#TimeUsernameProblemLanguageResultExecution timeMemory
789477AcanikolicJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
265 ms21736 KiB
#include <bits/stdc++.h> #define ll long long #define int long long #define pb push_back #define F first #define S second using namespace std; const long long N = 2e5+10; const long long mod = 1e9+7; const long long inf = 1e18; vector<int>a(N); bool cmp(int i,int j) { return a[i] < a[j]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int>b(n+1); for(int i=1;i<=n+1;i++) cin >> a[i]; for(int i=1;i<=n;i++) cin >> b[i]; sort(b.begin()+1,b.end()); vector<int>order(n+2),ans(n+2); iota(order.begin()+1,order.end(),1); sort(order.begin()+1,order.end(),cmp); multiset<int>ms; for(int i=2;i<=n+1;i++) ms.insert(max(0ll,a[order[i]]-b[i-1])); //for(int i=1;i<=n+1;i++) cout << a[order[i]] << ' '; for(int i=1;i<=n+1;i++) { //cout << order[i] << ' '; ans[order[i]] = *(--ms.end()); if(i <= n) ms.erase(ms.find(max(0ll,a[order[i+1]]-b[i]))); if(i <= n) ms.insert(max(0ll,a[order[i]]-b[i])); } for(int i=1;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...