#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
#define sqrt sqrtl
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, m, a[ 200001 ], l, r, x;
set <pair<int, int> > st;
int an[ 200001 ];
main () {
cin >> n >> m;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ];
if ( i > 1 )
st.insert( { a[ i ] - a[ i - 1 ], i - 1 } );
}
while ( m -- ) {
cin >> x;
num += x;
l = min( l, num );
r = max( r, num );
while ( st.size() && st.begin()->first < ( -l ) + r ) {
pos = st.begin()->second;
if ( num > 0 ) {
an[ pos + 1 ] += -l;
an[ pos ] += st.begin()->first + l;
}
else {
an[ pos ] += r;
an[ pos + 1 ] += st.begin()->first - r;
}
st.erase( st.begin() );
}
}
an[ 1 ] += -l;
an[ n ] += r;
while ( st.size() ) {
pos = st.begin()->second;
an[ pos ] += r;
an[ pos + 1 ] += ( -l );
st.erase( st.begin() );
}
for ( int i = 1; i <= n; i ++ )
cout << an[ i ] << "\n";
}
/*
*/
Compilation message
Main.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main () {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
448 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
448 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
79 ms |
2380 KB |
Output is correct |
21 |
Correct |
72 ms |
2200 KB |
Output is correct |
22 |
Correct |
70 ms |
1996 KB |
Output is correct |
23 |
Correct |
66 ms |
1968 KB |
Output is correct |
24 |
Correct |
74 ms |
3640 KB |
Output is correct |
25 |
Correct |
308 ms |
21200 KB |
Output is correct |
26 |
Correct |
275 ms |
21092 KB |
Output is correct |
27 |
Correct |
305 ms |
20812 KB |
Output is correct |
28 |
Correct |
301 ms |
20892 KB |
Output is correct |
29 |
Correct |
268 ms |
20484 KB |
Output is correct |
30 |
Correct |
233 ms |
19788 KB |
Output is correct |
31 |
Correct |
196 ms |
19372 KB |
Output is correct |
32 |
Correct |
187 ms |
19392 KB |
Output is correct |
33 |
Correct |
24 ms |
2420 KB |
Output is correct |
34 |
Correct |
280 ms |
21560 KB |
Output is correct |
35 |
Correct |
284 ms |
20952 KB |
Output is correct |
36 |
Correct |
276 ms |
21192 KB |
Output is correct |
37 |
Correct |
288 ms |
20932 KB |
Output is correct |
38 |
Correct |
288 ms |
20808 KB |
Output is correct |
39 |
Correct |
264 ms |
21072 KB |
Output is correct |
40 |
Correct |
221 ms |
21020 KB |
Output is correct |
41 |
Correct |
103 ms |
2984 KB |
Output is correct |
42 |
Correct |
299 ms |
19384 KB |
Output is correct |
43 |
Correct |
281 ms |
22696 KB |
Output is correct |
44 |
Correct |
102 ms |
2892 KB |
Output is correct |
45 |
Correct |
290 ms |
20908 KB |
Output is correct |
46 |
Correct |
338 ms |
22860 KB |
Output is correct |
47 |
Correct |
290 ms |
23064 KB |
Output is correct |
48 |
Correct |
281 ms |
23108 KB |
Output is correct |