Submission #955171

#TimeUsernameProblemLanguageResultExecution timeMemory
955171jcelinJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
73 ms17232 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vll; typedef vector<pll> vpll; #define PB push_back #define PF push_front<< #define PPB pop_back #define PPF pop_front #define X first #define Y second #define MP make_pair #define all(x) (x).begin(), (x).end() const int mod = 1e9 + 7; //998244353; const int inf = 1e9 + 7; const ll INF = 1e18 + 7; const int logo = 20; const int MAXN = 1e6 + 7; const int off = 1 << logo; const int trsz = off << 1; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; vii arr; vi b; int pf[MAXN], sf[MAXN], ans[MAXN]; void solve(){ int n; cin >> n; arr.resize(n + 1); for(int i=0; i<n+1; i++){ cin >> arr[i].X; arr[i].Y = i; } sort(all(arr)); b.resize(n); for(auto &x : b) cin >> x; sort(all(b)); for(int i=0; i<n; i++){ pf[i] = arr[i].X - b[i]; if(i) pf[i] = max(pf[i], pf[i - 1]); } for(int i=n-1; i>=0; i--){ sf[i] = arr[i + 1].X - b[i]; sf[i] = max(sf[i], sf[i + 1]); } for(int i=0; i<n+1; i++){ int vl = sf[i]; if(i) vl = max(vl, pf[i - 1]); ans[arr[i].Y] = vl; } for(int i=0; i<n+1; i++) cout << ans[i] << ' '; cout << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tt = 1; //cin >> tt; while(tt--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...