Submission #566957

#TimeUsernameProblemLanguageResultExecution timeMemory
566957RifalJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
277 ms10012 KiB
#include <bits/stdc++.h> #include <fstream> #define endl '\n' #define mod 32768 #define INF 100000000000000 //#define ll long long //#define cin fin //#define cout fout using namespace std; //ofstream fout("convention.out"); //ifstream fin("convention.in"); int main() { int n; cin >> n; long long mx = 0; pair<long long, int> a[n+1]; long long b[n], ans[n+1], cur[n]; for(int i = 0; i < n+1; i++) { cin >> a[i].first; a[i].second = i; } for(int i = 0; i < n; i++) { cin >> b[i]; } sort(a,a+n+1); sort(b,b+n); for(int i = n-1; i >= 0; i--) { cur[i] = max(a[i].first-b[i],0ll); mx = max(mx,cur[i]); } ans[a[n].second] = mx; for(int i = n-1; i >= 0; i--) { cur[i] = max(a[i+1].first-b[i],0ll); mx = max(mx,cur[i]); ans[a[i].second] = mx; } for(int i = 0; i < n+1; i++) { cout << ans[i] << ' '; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...