#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;
int n, q;
ll x[N];
ll w[N];
ll p[N];
ll maxu[N], minu[N];
void solv()
{
cin >> n >> q;
for (int i = 1; i <= n; ++i)
cin >> x[i];
for (int i = 1; i <= q; ++i)
cin >> w[i];
for (int i = 1; i <= q; ++i)
p[i] = p[i - 1] + w[i];
for (int i = 1; i <= q; ++i)
{
minu[i] = min(minu[i - 1], p[i]);
maxu[i] = max(maxu[i - 1], p[i]);
}
for (int i = 1; i <= n; ++i)
{
ll ans = 0;
if (i == 1)
{
ans -= minu[q];
}
else
{
int l = 1, r = q;
int u = 0;
while (l <= r)
{
int m = (l + r) / 2;
if (maxu[m] - minu[m] <= x[i] - x[i - 1])
{
u = m;
l = m + 1;
}
else
r = m - 1;
}
int m = u;
if (m == q || p[m + 1] > 0)
{
ans -= minu[m];
}
else
{
ans += (x[i] - x[i - 1] - maxu[m]);
}
}
if (i == n)
{
ans += maxu[q];
}
else
{
int l = 1, r = q;
int u = 0;
while (l <= r)
{
int m = (l + r) / 2;
if (maxu[m] - minu[m] <= x[i + 1] - x[i])
{
u = m;
l = m + 1;
}
else
r = m - 1;
}
int m = u;
if (m == q || p[m + 1] < 0)
{
ans += maxu[m];
}
else
{
ans += (x[i + 1] - x[i] + minu[m]);
}
}
cout << ans << "\n";
}
}
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // SOMETHING
ios_base::sync_with_stdio(false), cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)
{
solv();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
448 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 |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
448 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 |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
27 ms |
6576 KB |
Output is correct |
21 |
Correct |
30 ms |
6516 KB |
Output is correct |
22 |
Correct |
27 ms |
6544 KB |
Output is correct |
23 |
Correct |
23 ms |
6612 KB |
Output is correct |
24 |
Correct |
31 ms |
6916 KB |
Output is correct |
25 |
Correct |
131 ms |
9836 KB |
Output is correct |
26 |
Correct |
123 ms |
9720 KB |
Output is correct |
27 |
Correct |
120 ms |
9452 KB |
Output is correct |
28 |
Correct |
119 ms |
9448 KB |
Output is correct |
29 |
Correct |
133 ms |
9248 KB |
Output is correct |
30 |
Correct |
111 ms |
8836 KB |
Output is correct |
31 |
Correct |
67 ms |
8512 KB |
Output is correct |
32 |
Correct |
71 ms |
8568 KB |
Output is correct |
33 |
Correct |
12 ms |
1236 KB |
Output is correct |
34 |
Correct |
124 ms |
9680 KB |
Output is correct |
35 |
Correct |
115 ms |
9512 KB |
Output is correct |
36 |
Correct |
130 ms |
9656 KB |
Output is correct |
37 |
Correct |
121 ms |
9420 KB |
Output is correct |
38 |
Correct |
115 ms |
9492 KB |
Output is correct |
39 |
Correct |
121 ms |
9544 KB |
Output is correct |
40 |
Correct |
86 ms |
9420 KB |
Output is correct |
41 |
Correct |
27 ms |
6608 KB |
Output is correct |
42 |
Correct |
57 ms |
8452 KB |
Output is correct |
43 |
Correct |
83 ms |
9676 KB |
Output is correct |
44 |
Correct |
29 ms |
6456 KB |
Output is correct |
45 |
Correct |
71 ms |
9500 KB |
Output is correct |
46 |
Correct |
77 ms |
9804 KB |
Output is correct |
47 |
Correct |
77 ms |
9760 KB |
Output is correct |
48 |
Correct |
79 ms |
9792 KB |
Output is correct |