답안 #384952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384952 2021-04-02T18:07:17 Z timmyfeng Snowball (JOI21_ho_t2) C++17
100 / 100
125 ms 12268 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;

    vector<long long> x(n);
    for (auto &i : x) {
        cin >> i;
    }

    long long total = 0;
    vector<long long> left(q + 1), right(q + 1);
    for (int i = 0; i < q; ++i) {
        long long w;
        cin >> w;
        total += w;
        left[i + 1] = max(-total, left[i]);
        right[i + 1] = max(total, right[i]);
    }

    long long prv = left[q];
    for (int i = 1; i < n; ++i) {
        int low = 0, high = q;
        while (low < high) {
            int mid = (low + high + 1) / 2;
            if (left[mid] + right[mid] <= x[i] - x[i - 1]) {
                low = mid;
            } else {
                high = mid - 1;
            }
        }

        if (high == q) {
            cout << prv + right[q] << "\n";
            prv = left[q];
        } else if (left[high] == left[high + 1]) {
            cout << prv + x[i] - x[i - 1] - left[high] << "\n";
            prv = left[high];
        } else {
            cout << prv + right[high] << "\n";
            prv = x[i] - x[i - 1] - right[high];
        }
    }

    cout << prv + right[q] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 492 KB Output is correct
16 Correct 3 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 492 KB Output is correct
16 Correct 3 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 31 ms 5612 KB Output is correct
21 Correct 30 ms 5356 KB Output is correct
22 Correct 29 ms 5228 KB Output is correct
23 Correct 28 ms 5100 KB Output is correct
24 Correct 34 ms 5484 KB Output is correct
25 Correct 124 ms 10348 KB Output is correct
26 Correct 116 ms 10348 KB Output is correct
27 Correct 118 ms 10092 KB Output is correct
28 Correct 121 ms 10132 KB Output is correct
29 Correct 112 ms 9580 KB Output is correct
30 Correct 107 ms 9068 KB Output is correct
31 Correct 83 ms 8556 KB Output is correct
32 Correct 86 ms 8556 KB Output is correct
33 Correct 12 ms 1388 KB Output is correct
34 Correct 125 ms 10732 KB Output is correct
35 Correct 121 ms 10092 KB Output is correct
36 Correct 119 ms 10348 KB Output is correct
37 Correct 115 ms 10240 KB Output is correct
38 Correct 116 ms 9964 KB Output is correct
39 Correct 122 ms 10220 KB Output is correct
40 Correct 87 ms 10092 KB Output is correct
41 Correct 34 ms 6252 KB Output is correct
42 Correct 70 ms 8556 KB Output is correct
43 Correct 95 ms 11884 KB Output is correct
44 Correct 36 ms 6148 KB Output is correct
45 Correct 83 ms 10092 KB Output is correct
46 Correct 98 ms 12012 KB Output is correct
47 Correct 107 ms 12268 KB Output is correct
48 Correct 99 ms 12268 KB Output is correct