/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const ll inf = 1e17;
const int maxn = 2e5 + 10;
int n, q;
ll a[maxn], flf[maxn], frf[maxn], ans[maxn];
void solve()
{
cin >> n >> q;
for (int i = 1; i <= n; i ++)
cin >> a[i];
a[0] = - inf;
a[n + 1] = inf;
for (int i = 1; i <= n; i ++)
{
flf[i] = 1;
frf[i] = 1;
}
ll pos = 0, dlf = 0, drf = 0;
for (int i = 1; i <= q; i ++)
{
ll x;
cin >> x;
pos += x;
if (pos <= drf && pos >= dlf)
continue;
if (pos > drf)
{
drf = pos;
for (int j = 1; j <= n; j ++)
{
if (frf[j])
{
if (drf + abs(dlf) >= a[j + 1] - a[j])
{
///cout << j << " : " << i << " ::: " << dlf << endl;
ans[j] = ans[j] + (a[j + 1] - a[j] - abs(dlf));
frf[j] = 0;
}
}
if (flf[j])
{
if (drf + abs(dlf) >= a[j] - a[j - 1])
{
ans[j] = ans[j] + abs(dlf);
flf[j] = 0;
}
}
}
}
else
if (pos < dlf)
{
dlf = pos;
for (int j = 1; j <= n; j ++)
{
if (frf[j])
{
if (drf + abs(dlf) >= a[j + 1] - a[j])
{
ans[j] = ans[j] + drf;
frf[j] = 0;
}
}
if (flf[j])
{
if (drf + abs(dlf) >= a[j] - a[j - 1])
{
ans[j] = ans[j] + (a[j] - a[j - 1] - drf);
flf[j] = 0;
}
}
}
}
}
for (int i = 1; i <= n; i ++)
{
ll sum = ans[i];
if (flf[i] == 1)
sum = sum + abs(dlf);
if (frf[i] == 1)
sum = sum + drf;
cout << sum << endl;
}
}
int main()
{
solve();
return 0;
}
/**
4 3
-2 3 5 8
2
-4
7
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
17 ms |
432 KB |
Output is correct |
5 |
Correct |
17 ms |
432 KB |
Output is correct |
6 |
Correct |
18 ms |
424 KB |
Output is correct |
7 |
Correct |
15 ms |
360 KB |
Output is correct |
8 |
Correct |
14 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
420 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
356 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
17 ms |
340 KB |
Output is correct |
16 |
Correct |
18 ms |
448 KB |
Output is correct |
17 |
Correct |
15 ms |
484 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 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 |
320 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
17 ms |
432 KB |
Output is correct |
5 |
Correct |
17 ms |
432 KB |
Output is correct |
6 |
Correct |
18 ms |
424 KB |
Output is correct |
7 |
Correct |
15 ms |
360 KB |
Output is correct |
8 |
Correct |
14 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
420 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
356 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
17 ms |
340 KB |
Output is correct |
16 |
Correct |
18 ms |
448 KB |
Output is correct |
17 |
Correct |
15 ms |
484 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
115 ms |
2380 KB |
Output is correct |
21 |
Correct |
81 ms |
2208 KB |
Output is correct |
22 |
Correct |
186 ms |
1960 KB |
Output is correct |
23 |
Correct |
1488 ms |
1884 KB |
Output is correct |
24 |
Execution timed out |
2582 ms |
1552 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |