#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define pl pair<ll, ll>
#define f1 first
#define s2 second
const int MAX = 2e5 + 7;
int n, m;
ll X[MAX], res[MAX], kaze[MAX];
int main()
{
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> X[i];
for (int i = 1; i <= m; ++i)
cin >> kaze[i], kaze[i] += kaze[i-1];
vector<pl> v;
for (int i = 1; i+1 <= n; ++i)
v.pb({X[i+1] - X[i], i});
sort(v.begin(), v.end());
int idx = 0;
ll l = 0, r = 0; //l: west to east, r: east to west
for (int i = 1; i <= m; ++i)
{
if (kaze[i] < 0) //add something to r
{
while (idx < n-1 && l + max(r, -kaze[i]) >= v[idx].f1)
{
res[v[idx].s2] += l;
res[v[idx].s2 + 1] += v[idx].f1 - l;
idx++;
}
r = max(r, -kaze[i]);
}
else
{
while (idx < n-1 && r + max(l, kaze[i]) >= v[idx].f1)
{
res[v[idx].s2] += v[idx].f1 - r;
res[v[idx].s2 + 1] += r;
idx++;
}
l = max(l, kaze[i]);
}
}
while (idx < n-1)
{
res[v[idx].s2] += l;
res[v[idx].s2 + 1] += r;
idx++;
}
res[1] += r, res[n] += l;
for (int i = 1; i <= n; ++i)
cout << res[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
2 ms |
456 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
456 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
2 ms |
456 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
456 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
37 ms |
4008 KB |
Output is correct |
21 |
Correct |
34 ms |
3792 KB |
Output is correct |
22 |
Correct |
40 ms |
3644 KB |
Output is correct |
23 |
Correct |
28 ms |
3468 KB |
Output is correct |
24 |
Correct |
34 ms |
4340 KB |
Output is correct |
25 |
Correct |
104 ms |
13524 KB |
Output is correct |
26 |
Correct |
108 ms |
13456 KB |
Output is correct |
27 |
Correct |
104 ms |
13120 KB |
Output is correct |
28 |
Correct |
113 ms |
13244 KB |
Output is correct |
29 |
Correct |
134 ms |
12816 KB |
Output is correct |
30 |
Correct |
98 ms |
12172 KB |
Output is correct |
31 |
Correct |
94 ms |
11624 KB |
Output is correct |
32 |
Correct |
83 ms |
11780 KB |
Output is correct |
33 |
Correct |
12 ms |
1796 KB |
Output is correct |
34 |
Correct |
112 ms |
13916 KB |
Output is correct |
35 |
Correct |
105 ms |
13268 KB |
Output is correct |
36 |
Correct |
102 ms |
13488 KB |
Output is correct |
37 |
Correct |
103 ms |
13336 KB |
Output is correct |
38 |
Correct |
104 ms |
13104 KB |
Output is correct |
39 |
Correct |
103 ms |
13312 KB |
Output is correct |
40 |
Correct |
105 ms |
13364 KB |
Output is correct |
41 |
Correct |
34 ms |
4604 KB |
Output is correct |
42 |
Correct |
90 ms |
11800 KB |
Output is correct |
43 |
Correct |
122 ms |
15024 KB |
Output is correct |
44 |
Correct |
38 ms |
4472 KB |
Output is correct |
45 |
Correct |
104 ms |
13300 KB |
Output is correct |
46 |
Correct |
104 ms |
15160 KB |
Output is correct |
47 |
Correct |
105 ms |
15352 KB |
Output is correct |
48 |
Correct |
101 ms |
15460 KB |
Output is correct |