답안 #201609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201609 2020-02-11T12:11:14 Z waynetuinfor Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
128 ms 7032 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  std::cin >> n;
  std::vector<int> a(n + 1), b(n), od(n + 1);
  for (int i = 0; i < n + 1; ++i) std::cin >> a[i];
  for (int i = 0; i < n; ++i) std::cin >> b[i];
  std::sort(b.begin(), b.end());
  std::iota(od.begin(), od.end(), 0);
  std::sort(od.begin(), od.end(), [&a](int i, int j) { return a[i] < a[j]; });
  std::vector<int> pref(n), suff(n + 1);
  for (int i = 0; i < n; ++i) {
    pref[i] = std::max(0, a[od[i]] - b[i]);
    if (i > 0) pref[i] = std::max(pref[i], pref[i - 1]);
  }
  for (int i = n; i > 0; --i) {
    suff[i] = std::max(0, a[od[i]] - b[i - 1]);
    if (i < n) suff[i] = std::max(suff[i], suff[i + 1]);
  }
  std::vector<int> ans(n + 1);
  for (int i = 0; i < n + 1; ++i) {
    int g = 0;
    if (i > 0) g = std::max(g, pref[i - 1]);
    if (i + 1 <= n) g = std::max(g, suff[i + 1]);
    ans[od[i]] = g;
  }
  for (int i = 0; i < n + 1; ++i) std::cout << ans[i] << " ";
  std::cout << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 300 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 300 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 7 ms 376 KB Output is correct
21 Correct 6 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 380 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 6 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 300 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 7 ms 376 KB Output is correct
21 Correct 6 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 380 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 6 ms 380 KB Output is correct
33 Correct 114 ms 6368 KB Output is correct
34 Correct 128 ms 6648 KB Output is correct
35 Correct 113 ms 6396 KB Output is correct
36 Correct 120 ms 6776 KB Output is correct
37 Correct 119 ms 7032 KB Output is correct
38 Correct 126 ms 7032 KB Output is correct
39 Correct 122 ms 6008 KB Output is correct
40 Correct 115 ms 6008 KB Output is correct
41 Correct 120 ms 6264 KB Output is correct
42 Correct 122 ms 6136 KB Output is correct
43 Correct 119 ms 6008 KB Output is correct
44 Correct 117 ms 5752 KB Output is correct
45 Correct 119 ms 5756 KB Output is correct
46 Correct 120 ms 5752 KB Output is correct
47 Correct 104 ms 5624 KB Output is correct
48 Correct 97 ms 5568 KB Output is correct
49 Correct 123 ms 6240 KB Output is correct
50 Correct 122 ms 6300 KB Output is correct
51 Correct 119 ms 6264 KB Output is correct
52 Correct 126 ms 6264 KB Output is correct
53 Correct 125 ms 6264 KB Output is correct