# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
878033 | frostray8653 | Snowball (JOI21_ho_t2) | C++17 | 13 ms | 844 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("Ofast,unroll-loops,O3")
#include <bits/stdc++.h>
#define int long long
// #define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IO ios::sync_with_stdio(0), cin.tie(0)
#define FOR(i, a, b) for (int i = a, I = b; i <= b; i++)
using namespace std;
void dbg() {;}
template<class T, class ...U>
void dbg(T a, U ...b) {cout << a << " "; dbg(b...);}
void ent() {cout << "\n";}
const int mod = 998244353;
// const int mod = 1e9 + 7;
// const int INF = 2e9;
const int INF = 1e18;
/// ------- Initialization End -------
const int N = 2005;
int a[N];
int dx[N];
signed main() {
IO;
int n, m;
cin >> n >> m;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, m) cin >> dx[i];
a[0] = -INF;
a[n + 1] = INF;
FOR(i, 1, n) {
int l_lim = -INF, r_lim = INF;
int l = a[i], r = a[i];
int now = a[i], bef = a[i - 1], nxt = a[i + 1];
FOR(j, 1, m) {
if (dx[j] > 0) {
r_lim = min(r_lim, nxt);
nxt += dx[j];
r = max(r, min(r_lim, now + dx[j]));
now += dx[j];
bef += dx[j];
l_lim = max(l_lim, bef);
} else {
l_lim = max(l_lim, bef);
bef += dx[j];
l = min(l, max(l_lim, now + dx[j]));
now += dx[j];
nxt += dx[j];
r_lim = min(r_lim, nxt);
}
}
cout << r - l << "\n";
}
/*
4 3
-2 3 5 8
2
-4
7
*/
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |