Submission #961436

#TimeUsernameProblemLanguageResultExecution timeMemory
961436mannshah1211Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
82 ms10836 KiB
/**
 *  author: hashman
 *  created: 
**/

#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
   if (!first) {
    res += ", ";
   }
   first = false;
   res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() {
  cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n + 1);
  vector<int> b(n);
  for (int i = 0; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  vector<int> ans(n + 1), p(n + 1), s(n + 1);
  for (int i = 0; i < n; i++) {
    p[i] = max(((i > 0) ? p[i - 1] : 0), a[i].first - b[i]);
  }
  for (int i = n; i >= 1; i--) {
    s[i] = max(((i < n) ? s[i + 1] : 0), a[i].first - b[i - 1]);
  }
  for (int i = 0; i <= n; i++) {
    int cur = 0;
    if (i > 0) {
      cur = max(cur, p[i - 1]);
    }
    if (i < n) {
      cur = max(cur, s[i + 1]);
    }
    ans[a[i].second] = cur;
  }
  for (int i = 0; i <= n; i++) {
    cout << ans[i] << " ";
  }
  cout << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...