Submission #208631

#TimeUsernameProblemLanguageResultExecution timeMemory
208631eriksuenderhaufJust Long Neckties (JOI20_ho_t1)C++11
100 / 100
170 ms7160 KiB
// #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define pb push_back #define sz(x) (int)(x).size() #define trav(x, a) for (const auto& x: a) #define pii pair<int,int> #define st first #define nd second using namespace std; typedef long long ll; const int N = 2e5 + 5; int a[N], b[N], ind[N]; int mP[N], mS[N], ans[N]; int main() { int n; scanf("%d", &n); for (int i = 0; i <= n; i++) scanf("%d", a+i), ind[i] = i; for (int i = 0; i < n; i++) scanf("%d", b+i); sort(b,b+n); sort(ind,ind+n+1,[](int l, int r) { return a[l] < a[r]; }); for (int i = 0; i < n; i++) mP[i] = !i ? max(a[ind[i]]-b[i],0) : max(mP[i-1], max(a[ind[i]]-b[i],0)); for (int i = n; i; i--) mS[i] = i==n ? max(a[ind[i]]-b[i-1],0) : max(mS[i+1], max(a[ind[i]]-b[i-1],0)); ans[ind[0]] = mS[1]; for (int i = 1; i < n; i++) ans[ind[i]] = max(mP[i-1],mS[i+1]); ans[ind[n]] = mP[n-1]; for (int i = 0; i <= n; i++) printf("%d ", ans[i]); }

Compilation message (stderr)

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