Submission #359882

#TimeUsernameProblemLanguageResultExecution timeMemory
359882shahriarkhanJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
165 ms11868 KiB
#include<bits/stdc++.h> using namespace std ; int main() { int n ; scanf("%d",&n) ; int a[n+1] , b[n+1] , pref[n+2] = {0} , suf[n+2] = {0} , ans[n+2] = {0} ; vector<pair<int,int> > v ; v.push_back({0,0}) ; for(int i = 1 ; i <= (n+1) ; ++i) { scanf("%d",&a[i]) ; v.push_back({a[i],i}) ; } for(int i = 1 ; i <= n ; ++i) scanf("%d",&b[i]) ; sort(v.begin()+1,v.end()) ; sort(b+1,b+n+1) ; for(int i = 1 ; i <= n ; ++i) { pref[i] = max(pref[i-1],v[i].first-b[i]) ; } for(int i = n ; i >= 1 ; --i) { suf[i] = max(suf[i+1],v[i+1].first-b[i]) ; } for(int i = 1 ; i <= (n+1) ; ++i) { ans[v[i].second] = max(pref[i-1],suf[i]) ; } for(int i = 1 ; i <= (n+1) ; ++i) printf("%d ",ans[i]) ; printf("\n") ; return 0 ; }

Compilation message (stderr)

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |     scanf("%d",&n) ;
      |     ~~~~~^~~~~~~~~
ho_t1.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |         scanf("%d",&a[i]) ;
      |         ~~~~~^~~~~~~~~~~~
ho_t1.cpp:16:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |     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...