Submission #761482

# Submission time Handle Problem Language Result Execution time Memory
761482 2023-06-19T19:01:34 Z sysia Snowball (JOI21_ho_t2) C++17
100 / 100
79 ms 16896 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;

void solve(){
    int n, m; cin >> n >> m;
    vector<int>a(n+1);
    for (int i = 1; i<=n; i++) cin >> a[i];
    vector<int>ans(n+1);
    vector<int>w(m+1), mn(m+1), mx(m+1), pref(m+1);
    for (int i = 1; i<=m; i++){
        cin >> w[i];
        pref[i] = pref[i-1] + w[i];
        mn[i] = min(pref[i], mn[i-1]);
        mx[i] = max(pref[i], mx[i-1]);
    }
    ans[1] -= mn.back();
    ans[n] += mx.back();
    debug(mn, mx);
    for (int i = 1; i<n; i++){
        int l = 0, r = m;
        int curr = 0;
        while (r >= l){
            int mid = (l+r)/2;
            if (mx[mid] + a[i] >= mn[mid] + a[i+1]){
                r = mid-1;
            } else {
                curr = mid;
                l = mid+1;
            }
        }
        
        //curr -- ostatni taki indeks
        if (curr == m){
            ans[i] += max(0ll, mx.back());
            ans[i+1] += max(0ll, -mn.back());
        } else {
            int d = a[i+1]-a[i];
            // debug(i, curr, mn[curr], mx[curr], w[curr+1]);
            if (w[curr+1] < 0){
                int tt = min(d, max(0ll, mx[curr]));
                ans[i] += tt;
                debug(tt, d-tt);
                ans[i+1] += d-tt;
            } else {
                int tt = min(d, max(0ll, -mn[curr]));
                ans[i+1] += tt;
                ans[i] += d-tt;
                debug(d-tt, tt);
            }
            debug(ans[i]);
        }
    }
    for (int i = 1; i<=n; i++) cout << ans[i] << "\n";
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 21 ms 8636 KB Output is correct
21 Correct 24 ms 8504 KB Output is correct
22 Correct 22 ms 8328 KB Output is correct
23 Correct 17 ms 8136 KB Output is correct
24 Correct 22 ms 8660 KB Output is correct
25 Correct 79 ms 14996 KB Output is correct
26 Correct 75 ms 14928 KB Output is correct
27 Correct 79 ms 14516 KB Output is correct
28 Correct 76 ms 14696 KB Output is correct
29 Correct 75 ms 14264 KB Output is correct
30 Correct 72 ms 13648 KB Output is correct
31 Correct 50 ms 13084 KB Output is correct
32 Correct 44 ms 13140 KB Output is correct
33 Correct 7 ms 1760 KB Output is correct
34 Correct 78 ms 15320 KB Output is correct
35 Correct 79 ms 14684 KB Output is correct
36 Correct 76 ms 14972 KB Output is correct
37 Correct 79 ms 14676 KB Output is correct
38 Correct 74 ms 14516 KB Output is correct
39 Correct 74 ms 14788 KB Output is correct
40 Correct 53 ms 14796 KB Output is correct
41 Correct 22 ms 9260 KB Output is correct
42 Correct 43 ms 13128 KB Output is correct
43 Correct 56 ms 16484 KB Output is correct
44 Correct 21 ms 9140 KB Output is correct
45 Correct 49 ms 14688 KB Output is correct
46 Correct 57 ms 16600 KB Output is correct
47 Correct 72 ms 16896 KB Output is correct
48 Correct 57 ms 16868 KB Output is correct