제출 #1310025

#제출 시각아이디문제언어결과실행 시간메모리
1310025syanvuJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
69 ms11772 KiB
// #pragma optimize ("g",on) // #pragma GCC optimize ("inline") // #pragma GCC optimize ("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC optimize ("03") #include <bits/stdc++.h> #define pb push_back #define SS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #define int long long #define all(v) v.begin(),v.end() using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const int N = 5e5 + 1, inf = 1e9, mod = 998244353; void solve(){ int n; cin >> n; pair<int, int> a[n + 2]; int b[n + 1] = {}; for(int i = 1; i <= n + 1; i++){ cin >> a[i].first; a[i].second = i; } for(int i = 1; i <= n; i++){ cin >> b[i]; } sort(b + 1, b + n + 1); sort(a + 1, a + n + 2); int suf[n + 3] = {}, pref[n + 3] = {}; for(int i = n + 1; i >= 2; i--){ auto [x, y] = a[i]; suf[i] = max(suf[i + 1], max(x - b[i - 1], 0ll)); } int ans[n + 2] = {}; for(int i = 1; i <= n; i++){ auto [x, y] = a[i]; pref[i] = max(pref[i - 1], max(x - b[i], 0ll)); } for(int i = 1; i <= n + 1; i++){ auto [x, y] = a[i]; ans[y] = max(pref[i - 1], suf[i + 1]); } for(int i = 1; i <= n + 1; i++){ cout << ans[i] << ' '; } } signed main(){ SS // freopen("trains.in", "r", stdin); // freopen("trains.out", "w", stdout); int t = 1; // cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...