Submission #566740

#TimeUsernameProblemLanguageResultExecution timeMemory
566740milisavJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
120 ms11640 KiB
#include<bits/stdc++.h> #define maxn 500000 using namespace std; int n; int a[maxn]; int b[maxn]; pair<int,int> ordr[maxn]; int ans[maxn]; int pref[maxn]; int suf[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=n+1;i++) { scanf("%d",&a[i]); ordr[i]={a[i],i}; } for(int i=1;i<=n;i++) scanf("%d",&b[i]); sort(a+1,a+(n+2)); sort(ordr+1,ordr+(n+2)); sort(b+1,b+(n+1)); for(int i=1;i<=n;i++) pref[i]=max(pref[i-1],max(a[i]-b[i],0)); for(int i=n;i>=1;i--) suf[i]=max(suf[i+1],max(a[i+1]-b[i],0)); for(int i=1;i<=n+1;i++) { ans[ordr[i].second] = max(pref[i-1],suf[i]); } for(int i=1;i<=n+1;i++) { printf("%d ",ans[i]); } return 0; }

Compilation message (stderr)

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
ho_t1.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
ho_t1.cpp:17:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     for(int i=1;i<=n;i++) scanf("%d",&b[i]);
      |                           ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...