Submission #1070890

# Submission time Handle Problem Language Result Execution time Memory
1070890 2024-08-22T20:27:38 Z dpsaveslives Snowball (JOI21_ho_t2) C++17
100 / 100
97 ms 15420 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5+10;
ll A[MAXN],W[MAXN],ans[MAXN],minp[MAXN],maxp[MAXN];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N,Q; cin >> N >> Q;
    ll psum = 0ll;
    for(int i = 1;i<=N;++i){
        cin >> A[i];
    }
    for(int i = 1;i<=Q;++i){
        cin >> W[i];
        psum += W[i];
        minp[i] = max(minp[i-1],-psum);
        maxp[i] = max(maxp[i-1],psum);
    }
    ans[1] += minp[Q]; ans[N] += maxp[Q];
    for(int i = 1;i<=N-1;++i){
        if(A[i+1]-A[i] >= maxp[Q]+minp[Q]){
            ans[i] += maxp[Q];
            ans[i+1] += minp[Q];
        }
        else{
            int lo = 1, hi = Q+1;
            while(lo < hi){
                int mid = lo+(hi-lo)/2;
                if(A[i+1]-A[i] < maxp[mid]+minp[mid]){
                    hi = mid;
                }
                else{
                    lo = mid+1;
                }
            }
            if(minp[lo] == minp[lo-1]){
                ans[i+1] += minp[lo];
                ans[i] += A[i+1]-A[i]-minp[lo];
            }
            else{
                ans[i+1] += A[i+1]-A[i]-maxp[lo];
                ans[i] += maxp[lo];
            }
        }
    }
    for(int i = 1;i<=N;++i){
        cout << ans[i] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4568 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4604 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4568 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4604 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 17 ms 8796 KB Output is correct
21 Correct 25 ms 8496 KB Output is correct
22 Correct 20 ms 8540 KB Output is correct
23 Correct 16 ms 8292 KB Output is correct
24 Correct 21 ms 8540 KB Output is correct
25 Correct 86 ms 13392 KB Output is correct
26 Correct 97 ms 13288 KB Output is correct
27 Correct 74 ms 13092 KB Output is correct
28 Correct 73 ms 13116 KB Output is correct
29 Correct 72 ms 12640 KB Output is correct
30 Correct 67 ms 12068 KB Output is correct
31 Correct 42 ms 11600 KB Output is correct
32 Correct 36 ms 11608 KB Output is correct
33 Correct 7 ms 5464 KB Output is correct
34 Correct 73 ms 13868 KB Output is correct
35 Correct 74 ms 13136 KB Output is correct
36 Correct 72 ms 13536 KB Output is correct
37 Correct 76 ms 13296 KB Output is correct
38 Correct 71 ms 13136 KB Output is correct
39 Correct 68 ms 13252 KB Output is correct
40 Correct 45 ms 13136 KB Output is correct
41 Correct 20 ms 9540 KB Output is correct
42 Correct 33 ms 11612 KB Output is correct
43 Correct 46 ms 14932 KB Output is correct
44 Correct 17 ms 9308 KB Output is correct
45 Correct 45 ms 13284 KB Output is correct
46 Correct 51 ms 15100 KB Output is correct
47 Correct 53 ms 15324 KB Output is correct
48 Correct 59 ms 15420 KB Output is correct