Submission #224022

#TimeUsernameProblemLanguageResultExecution timeMemory
224022SomeoneUnknownJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
165 ms7164 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; ii mii(int a, int b){ return make_pair(a,b); } int main(){ int n; scanf("%d", &n); ii nnt[n+1]; int ont[n]; for(int i = 0; i <= n; i++){ int x; scanf("%d", &x); nnt[i] = mii(x, i); } for(int i = 0; i < n; i++) scanf("%d", &ont[i]); sort(nnt, nnt+n+1); sort(ont, ont+n); ii dffs[n]; for(int i = 0; i < n; i++){ dffs[i] = mii(max(nnt[i+1].first-ont[i], 0), i); } sort(dffs, dffs+n); int rsidep = n-1; int lsidemax = 0; int ans[n+1]; //printf("%d", dffs[rsidep].first); ans[nnt[0].second] = dffs[rsidep].first; for(int i = 0; i < n; i++){ while(rsidep >= 0 && dffs[rsidep].second <= i){ rsidep--; } lsidemax = max(lsidemax, nnt[i].first-ont[i]); ans[nnt[i+1].second] = lsidemax; if(rsidep >= 0) ans[nnt[i+1].second] = max(dffs[rsidep].first, lsidemax); //printf("%d %d ", dffs[rsidep].first,) //printf("\n"); } for(int i = 0; i <= n; i++){ printf("%d ", ans[i]); } } /* 3 7 3 4 6 2 6 4 */

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]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
ho_t1.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
ho_t1.cpp:20:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0; i < n; i++) scanf("%d", &ont[i]);
                                ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...