Submission #244847

#TimeUsernameProblemLanguageResultExecution timeMemory
244847maximath_1Just Long Neckties (JOI20_ho_t1)C++11
100 / 100
185 ms7032 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n = 0; vector<int> a, b, id, pos, pref, suff; bool cmp(int x, int y){ return a[x] < a[y]; } int main(){ scanf("%d", &n); a.resize(n + 1); id.resize(n + 1); pos.resize(n + 1); b.resize(n); for(int i = 0; i <= n; i ++){ scanf("%d", &a[i]); id[i] = i; } for(int i = 0; i < n; i ++) scanf("%d", &b[i]); sort(id.begin(), id.end(), cmp); sort(a.begin(), a.end()); for(int i = 0; i <= n; i ++) pos[id[i]] = i; sort(b.begin(), b.end()); pref.assign(n + 1, 0); suff.assign(n + 1, 0); for(int i = 1; i <= n; i ++) pref[i] = max(pref[i - 1], a[i - 1] - b[i - 1]); for(int i = n - 1; i >= 0; i --) suff[i] = max(suff[i + 1], a[i + 1] - b[i]); for(int i = 0; i <= n; i ++) printf("%d%c", max(pref[pos[i]], suff[pos[i]]), i == n ? '\n' : ' '); return 0; }

Compilation message (stderr)

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