Submission #553984

#TimeUsernameProblemLanguageResultExecution timeMemory
553984AA_SurelyJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
108 ms10772 KiB
#include <bits/stdc++.h> #define FOR(i,x,n) for(int i=x; i<n; i++) #define F0R(i,n) FOR(i,0,n) #define ROF(i,x,n) for(int i=n-1; i>=x; i--) #define R0F(i,n) ROF(i,0,n) #define WTF cout << "WTF" << endl #define IOS ios::sync_with_stdio(false); cin.tie(0) #define F first #define S second #define pb push_back #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<LL> VLL; typedef vector<PII> VPII; typedef vector<PLL> VPLL; const int N = 2e5 + 7; const int ALPHA = 27; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int LOG = 22; int n; int neck[N], ppl[N]; int id[N], ans[N]; int rps[N], lps[N]; int main() { IOS; cin >> n; FOR(i, 1, n + 2) { cin >> neck[i]; id[i] = i; } FOR(i, 1, n + 1) cin >> ppl[i]; sort(id + 1, id + n + 2, [](const int a, const int b) {return neck[a] < neck[b];}); sort(neck + 1, neck + n + 2); sort(ppl + 1, ppl + n + 1); FOR(i, 1, n + 2) { rps[i + 1] = max(rps[i + 1], neck[i] - ppl[i]); lps[i - 1] = max(lps[i - 1], neck[i] - ppl[i - 1]); } FOR(i, 1, n + 2) rps[i] = max(rps[i], rps[i - 1]); R0F(i, n + 1) lps[i] = max(lps[i], lps[i + 1]); FOR(i, 1, n + 2) ans[ id[i] ] = max(rps[i], lps[i]); FOR(i, 1, n + 2) cout << ans[i] << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...