#include <bits/stdc++.h>
using namespace std;
#define int int64_t
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,q;
cin >> n >> q;
int x[n];
vector<pair<int,int>> cc;
vector<int> ans(n);
for(int i = 0;i < n;++i)
{
cin >> x[i];
if(i > 0)
{
cc.push_back({x[i]-x[i-1],i-1});
}
}
sort(cc.begin(),cc.end());
int yk = 0;
int lg = 0,rg = 0;
int w[q];
int sum = 0;
for(int i = 0;i < q;++i)
{
cin >> w[i];
sum += w[i];
if(sum < lg)
{
lg = sum;
while(yk < n-1 && cc[yk].first <= rg-lg)
{
ans[cc[yk].second] += rg;
ans[cc[yk].second+1] += cc[yk].first-rg;
yk++;
}
}
else if(sum > rg)
{
rg = sum;
while(yk < n-1 && cc[yk].first <= rg-lg)
{
// cout << cc[yk].second << ' ' << lg << ' ' << rg << "\n";
ans[cc[yk].second+1] += abs(lg);
ans[cc[yk].second] += cc[yk].first-abs(lg);
yk++;
}
}
}
while(yk < n-1)
{
ans[cc[yk].second+1] += abs(lg);
ans[cc[yk].second] += rg;
yk++;
}
ans[0] += abs(lg);
ans[n-1] += rg;
for(int i = 0;i < n;++i)
{
cout << ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
18 ms |
3932 KB |
Output is correct |
21 |
Correct |
18 ms |
3932 KB |
Output is correct |
22 |
Correct |
17 ms |
3672 KB |
Output is correct |
23 |
Correct |
18 ms |
3632 KB |
Output is correct |
24 |
Correct |
20 ms |
4572 KB |
Output is correct |
25 |
Correct |
66 ms |
13520 KB |
Output is correct |
26 |
Correct |
64 ms |
14268 KB |
Output is correct |
27 |
Correct |
62 ms |
13252 KB |
Output is correct |
28 |
Correct |
74 ms |
13360 KB |
Output is correct |
29 |
Correct |
64 ms |
12928 KB |
Output is correct |
30 |
Correct |
74 ms |
12364 KB |
Output is correct |
31 |
Correct |
58 ms |
12144 KB |
Output is correct |
32 |
Correct |
46 ms |
12744 KB |
Output is correct |
33 |
Correct |
7 ms |
1760 KB |
Output is correct |
34 |
Correct |
66 ms |
14220 KB |
Output is correct |
35 |
Correct |
63 ms |
13356 KB |
Output is correct |
36 |
Correct |
65 ms |
14536 KB |
Output is correct |
37 |
Correct |
66 ms |
13408 KB |
Output is correct |
38 |
Correct |
64 ms |
13768 KB |
Output is correct |
39 |
Correct |
67 ms |
14280 KB |
Output is correct |
40 |
Correct |
65 ms |
14008 KB |
Output is correct |
41 |
Correct |
20 ms |
4680 KB |
Output is correct |
42 |
Correct |
57 ms |
11976 KB |
Output is correct |
43 |
Correct |
60 ms |
15428 KB |
Output is correct |
44 |
Correct |
19 ms |
4436 KB |
Output is correct |
45 |
Correct |
61 ms |
13552 KB |
Output is correct |
46 |
Correct |
62 ms |
15296 KB |
Output is correct |
47 |
Correct |
65 ms |
16064 KB |
Output is correct |
48 |
Correct |
62 ms |
16408 KB |
Output is correct |