Submission #961436

# Submission time Handle Problem Language Result Execution time Memory
961436 2024-04-12T05:50:07 Z mannshah1211 Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
82 ms 10836 KB
/**
 *  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 time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 356 KB Output is correct
33 Correct 67 ms 9976 KB Output is correct
34 Correct 72 ms 10472 KB Output is correct
35 Correct 72 ms 10012 KB Output is correct
36 Correct 71 ms 10588 KB Output is correct
37 Correct 72 ms 10836 KB Output is correct
38 Correct 71 ms 10700 KB Output is correct
39 Correct 70 ms 10064 KB Output is correct
40 Correct 68 ms 9812 KB Output is correct
41 Correct 68 ms 9812 KB Output is correct
42 Correct 70 ms 9860 KB Output is correct
43 Correct 68 ms 9804 KB Output is correct
44 Correct 66 ms 9428 KB Output is correct
45 Correct 67 ms 9492 KB Output is correct
46 Correct 75 ms 9560 KB Output is correct
47 Correct 64 ms 9532 KB Output is correct
48 Correct 64 ms 9556 KB Output is correct
49 Correct 73 ms 9964 KB Output is correct
50 Correct 82 ms 10336 KB Output is correct
51 Correct 70 ms 9956 KB Output is correct
52 Correct 70 ms 10072 KB Output is correct
53 Correct 71 ms 10052 KB Output is correct