답안 #899319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899319 2024-01-05T18:35:39 Z Andrey Snowball (JOI21_ho_t2) C++14
100 / 100
83 ms 13888 KB
#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,q,a,b;
    cin >> n >> q;
    vector<long long> haha(n);
    for(long long i = 0; i < n; i++) {
        cin >> haha[i];
    }
    vector<pair<long long,long long>> wut(q+1);
    long long sm = 0,big = 0,sb = 0;
    for(long long i = 1; i <= q; i++) {
        cin >> a;
        sb+=a;
        sm = max(sm,-sb);
        big = max(big,sb);
        wut[i] = {sm,big};
    }
    vector<long long> ans(n);
    for(long long i = 0; i <= n; i++) {
        long long br;
        if(i == 0 || i == n) {
            br = LLONG_MAX;
        }
        else {
            br = haha[i]-haha[i-1];
        }
        long long l = 1,r = q;
        if(wut[q].first+wut[q].second < br) {
            a = wut[q].first;
            b = wut[q].second;
        }
        else {
            while(l < r) {
                long long m = (l+r)/2;
                if(wut[m].first+wut[m].second < br) {
                    l = m+1;
                }
                else {
                    r = m;
                }
            }
            if(wut[l].first == wut[l-1].first) {
                a = wut[l].first;
                b = br-a;
            }
            else {
                b = wut[l].second;
                a = br-b;
            }
        }
        if(i-1 >= 0) {
            ans[i-1]+=b;
        }
        if(i < n) {
            ans[i]+=a;
        }
    }
    for(long long i = 0; i < n; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 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 456 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 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 456 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 20 ms 5628 KB Output is correct
21 Correct 22 ms 5472 KB Output is correct
22 Correct 17 ms 5216 KB Output is correct
23 Correct 17 ms 5212 KB Output is correct
24 Correct 21 ms 5720 KB Output is correct
25 Correct 74 ms 11976 KB Output is correct
26 Correct 73 ms 11908 KB Output is correct
27 Correct 74 ms 11468 KB Output is correct
28 Correct 74 ms 11648 KB Output is correct
29 Correct 71 ms 11092 KB Output is correct
30 Correct 67 ms 10644 KB Output is correct
31 Correct 51 ms 10184 KB Output is correct
32 Correct 53 ms 10456 KB Output is correct
33 Correct 7 ms 1628 KB Output is correct
34 Correct 77 ms 12268 KB Output is correct
35 Correct 75 ms 11604 KB Output is correct
36 Correct 76 ms 11860 KB Output is correct
37 Correct 83 ms 11660 KB Output is correct
38 Correct 74 ms 11504 KB Output is correct
39 Correct 71 ms 11668 KB Output is correct
40 Correct 59 ms 11608 KB Output is correct
41 Correct 24 ms 6232 KB Output is correct
42 Correct 37 ms 10068 KB Output is correct
43 Correct 55 ms 13396 KB Output is correct
44 Correct 20 ms 5980 KB Output is correct
45 Correct 44 ms 11732 KB Output is correct
46 Correct 56 ms 13652 KB Output is correct
47 Correct 60 ms 13888 KB Output is correct
48 Correct 59 ms 13760 KB Output is correct