Submission #567040

#TimeUsernameProblemLanguageResultExecution timeMemory
567040MajidJust Long Neckties (JOI20_ho_t1)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; //Types using ll = long long; using db = double; //Vectors #define pb push_back #define sz(vec) ((ll)vec.size()) #define all(vec) vec.begin(), vec.end() //things #define f first #define s second const int SMALLINF = 1e9 + 7; const ll BIGINF = ((ll)1e18) + 7; #define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL); void solve(){ ll n; cin>>n; vector<ll> a(n+1), b(n); for(ll i = 0; i < n+1; i++){ cin>>a[i]; } for(ll i = 0; i < n; i++){ cin>>b[i]; } sort(all(a)); sort(all(b)); // vector<ll> prfx(n+1); // // for(ll i = n-1; i >= 0; i--){ // // prfx[i] = prfx[i+1] + (a[i+1] - a[i]); // } // // // for(ll i = 0; i < n; i++)cout<<prfx[i]<<" "; vector<ll> orig(n); ll mx = 0; for(ll i = 0; i < n; i++){ orig[i] = max(0ll, a[i] - b[i]); mx = max(mx, orig[i]); } vector<ll> ans(n+1), vec(n); map<ll, ll> mp; priority_queue<ll> pq; for(ll i = 0; i < n; i++){ pq.push(a[i+1] - b[i]); vec[i] = a[i+1] - b[i]; // cout<<vec[i]<<" "; mp[a[i+1] - b[i]]++; } // ans[0] = pq.top(); ans[n] = mx; for(ll i = 0; i < n; i++){ // cout<<vec[i]<<" "<<orig[i]<<"\n"; while(!pq.empty() and mp[pq.top()]<1){ // cout<<"POP"<<pq.top()<<"\n"; pq.pop(); } mp[vec[i]]--; mp[orig[i]]++; pq.push(orig[i]); ans[i] = pq.top(); } // ans[n] = orig; for(ll i = 0; i < n+1; i++)cout<<ans[i]<<" "; } int main(){ Speeed ll t=1; // cin>>t; while(t--){ solve(); } } // 3 // 3 4 6 7 // 2 4 6 // 4 // 1 8 12 17 20 // 3 7 10 13
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...