Submission #1279695

#TimeUsernameProblemLanguageResultExecution timeMemory
1279695yassiaJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
86 ms16624 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using str = string; using ld = long double; using hash_map = gp_hash_table<int, int>; using hash_set = gp_hash_table<int, null_type>; auto sd = std::chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rnd(sd); using ord_set = tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>; const ll inf = 1e18; void solve1() { ll n; cin >> n; vector<pll> a(n+1); vector<ll> a1; for (int i = 0; i <= n; i++){ cin>>a[i].first; a[i].second= i; a1.push_back(a[i].first); } sort(a1.begin(), a1.end()); vector<ll> b(n); for (int i =0; i<n;i++){ cin>>b[i]; } sort(b.begin(), b.end()); vector<ll> t1; vector<ll> t2; for (int i =0; i <n; i++){ t1.push_back(max(0ll,a1[i]-b[i])); } for(int j = 0; j <n;j++){ t2.push_back(max(0ll, a1[j+1]-b[j])); } vector<ll> pr_max(n+1); for (int j = 1; j <= n; j++){ pr_max[j] = max(pr_max[j-1], t1[j-1]); } vector<ll> sufmax(n+1); for (int j = n-1; j>=0 ;j--){ sufmax[j] = max(sufmax[j+1], t2[j]); } sort(a.begin(), a.end()); vector<ll> answs(n+1); for (int j =0; j<n+1; j++){ answs[a[j].second] = max(pr_max[j],sufmax[j]); } for (int j = 0; j< n+1; j++){ cout<<answs[j]<<" "; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef local freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int t1 = 1; // cin>>t1; for (int o_ = 0; o_ < t1; o_++) { solve1(); } #ifdef local printf_s("\n%.5f s", (double) clock() / CLOCKS_PER_SEC); #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...