Submission #599057

#TimeUsernameProblemLanguageResultExecution timeMemory
599057jmyszka2007Snowball (JOI21_ho_t2)C++17
100 / 100
133 ms12916 KiB
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 2 * 1e5;
typedef long long ll;
ll s[MAXN + 10];
ll mx[MAXN + 10];
ll mn[MAXN + 10];
ll tab[MAXN + 10];
ll w[MAXN + 10];
ll res[MAXN + 10];
int bs(int l, int r, ll x) {
    while(l < r) {
        int mid = (l + r + 1) / 2;
        if((mx[mid] - mn[mid]) <= x) {
            l = mid;
        }
        else {
            r = mid - 1;
        }
    }
    return l;
}
int main() {
    int n, t;
    scanf("%d%d", &n, &t);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &tab[i]);
    }
    for(int i = 1; i <= t; i++) {
        scanf("%lld", &w[i]);
        s[i] = s[i - 1] + w[i];
        mx[i] = max(mx[i - 1], s[i]);
        mn[i] = min(mn[i - 1], s[i]);
    }
    for(int i = 1; i < n; i++) {
        ll d = tab[i + 1] - tab[i];
        int m = bs(0, t, d);
        res[i] += mx[m];
        res[i + 1] += mn[m] * -1;
        if(m == t) {
            continue;
        }
        if(w[m + 1] >= 0) {
            res[i] += (d - mx[m] + mn[m]);
        }
        else {
            res[i + 1] += (d - mx[m] + mn[m]);
        }
    }
    res[1] += mn[t] * -1;
    res[n] += mx[t];
    for(int i = 1; i <= n; i++) {
        printf("%lld ", res[i]);
    }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d%d", &n, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%lld", &tab[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%lld", &w[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...