Submission #1045064

#TimeUsernameProblemLanguageResultExecution timeMemory
1045064NurislamJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
88 ms13952 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define int long long template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } const int N = 2e5+5, inf = 1e18, mod = 1e9+7; void solve(){ int n; cin >> n; vector<array<int,2>> a(n+1); int id = 0; for(auto &[i, j]:a){ cin >> i; j = id++; } vector<int> b(n); for(int &i:b)cin >> i; sort(all(a)); sort(all(b)); //for(auto i:a)cout << i[0] << ' '; //cout << '\n'; //for(auto i:b)cout << i << ' '; //cout << '\n'; vector<int> suf(n+2, 0); for(int i = n; i > 0; i--){ chmax(suf[i], suf[i+1]); chmax(suf[i], a[i][0] - b[i-1]); } //for(int i = 1; i <= n; i++)cout << suf[i] << ' '; //cout << '\n'; int pre = 0; vector<int> ans(n+1); for(int i = 0; i <= n; i++){ ans[a[i][1]] = max(pre, suf[i+1]); chmax(pre, a[i][0] - b[i]); } for(int i:ans)cout << i << ' '; cout << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tt = 1; //cin >> tt; while(tt--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...