제출 #853409

#제출 시각아이디문제언어결과실행 시간메모리
853409reginoxJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
111 ms15564 KiB
#include<bits/stdc++.h> #define ll long long #define sp << " " #define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task " " using namespace std; struct tmp{ ll id, ans, v; }; ll n, b[200005]; tmp a[200005]; ll t1[200005], t2[200005]; bool cmp2(tmp x, tmp y){ return x.id<y.id; } void sub1(){ ll c, ans; for(ll i = 1; i <= n+1; i++){ c = 1, ans = -1e18; for(ll j = 1; j <= n; j++){ if(c==i) c++; ans=max(ans, max(0ll, a[c].v-b[j])); c++; } a[i].ans = ans; } sort(a+1,a+n+2,cmp2); for(ll i = 1; i <= n+1; i++) cout << a[i].ans sp; } void sub2(){ for(ll i = 1; i <= n;i++){ t1[i]=a[i+1].v-b[i]; t2[i]=a[i].v-b[i]; } // for(ll i = 1; i <= n; i++){ // //cout << max(t1[i], t2[i-1]) sp; // cout << t1[i] sp << t2[i] << "\n"; // } for(ll i = 1; i <= n; i++) t2[i]=max(t2[i], t2[i-1]); for(ll i = n; i >= 1; i--) t1[i]=max(t1[i], t1[i+1]); for(ll i = 1; i <= n+1; i++){ a[i].ans = max(t1[i], t2[i-1]); //cout << t1[i] sp << t2[i] << "\n"; } sort(a+1,a+n+2,cmp2); for(ll i = 1; i <= n+1; i++) cout << a[i].ans sp; } bool cmp(tmp x, tmp y){ return x.v<y.v; } int main(){ faster //freopen(task".inp","r",stdin); //freopen(task".out","w",stdout); cin >> n; for(ll i = 1; i <= n+1; i++){ cin >> a[i].v; a[i].id=i; } for(ll j = 1; j <= n; j++) cin >> b[j]; sort(a+1,a+n+2, cmp); sort(b+1,b+n+1); if(n<=2000){ sub1(); } else{ sub2(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...