#include<bits/stdc++.h>
#define pb push_back
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
int n, q;
ll A[maxn], B[maxn];
vector<ll> L, R;
ll ansL[maxn], ansR[maxn];
int main() {
scanf("%d%d", &n, &q);
for(int i = 0;i < n;i++) scanf("%lld", A + i);
for(int i = 0;i < q;i++) scanf("%lld", B + i);
L.pb(min(0LL, B[0])), R.pb(max(0LL, B[0]));
ll x = B[0];
for(int i = 1;i < q;i++) {
x += B[i];
L.pb(min(L[i - 1], x));
R.pb(max(R[i - 1], x));
}
for(int i = 0;i < q;i++) L[i] = -L[i];
ansL[0] = L[q - 1];
for(int i = 1;i < n;i++) {
ll lo = 0, hi = 1e18;
while(lo <= hi) {
ll mid = (lo + hi) / 2;
int pos = lower_bound(all(L), mid) - L.begin();
if(pos != L.size() && mid + R[pos] <= A[i] - A[i - 1])
ansL[i] = mid, lo = mid + 1;
else hi = mid - 1;
}
}
ansR[n - 1] = R[q - 1];
for(int i = 0;i < n - 1;i++) {
ll lo = 0, hi = 1e18;
while(lo <= hi) {
ll mid = (lo + hi) / 2;
int pos = lower_bound(all(R), mid) - R.begin();
if(pos != R.size() && mid + L[pos] <= A[i + 1] - A[i])
ansR[i] = mid, lo = mid + 1;
else hi = mid - 1;
}
}
for(int i = 0;i < n;i++) printf("%lld\n", ansL[i] + ansR[i]);
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:37:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if(pos != L.size() && mid + R[pos] <= A[i] - A[i - 1])
| ~~~~^~~~~~~~~~~
Main.cpp:48:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | if(pos != R.size() && mid + L[pos] <= A[i + 1] - A[i])
| ~~~~^~~~~~~~~~~
Main.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:19:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | for(int i = 0;i < n;i++) scanf("%lld", A + i);
| ~~~~~^~~~~~~~~~~~~~~
Main.cpp:20:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | for(int i = 0;i < q;i++) scanf("%lld", B + i);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
496 KB |
Output is correct |
5 |
Correct |
6 ms |
456 KB |
Output is correct |
6 |
Correct |
6 ms |
456 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
6 ms |
496 KB |
Output is correct |
16 |
Correct |
6 ms |
500 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
4 ms |
468 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 |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
496 KB |
Output is correct |
5 |
Correct |
6 ms |
456 KB |
Output is correct |
6 |
Correct |
6 ms |
456 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
6 ms |
496 KB |
Output is correct |
16 |
Correct |
6 ms |
500 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
4 ms |
468 KB |
Output is correct |
20 |
Correct |
29 ms |
7320 KB |
Output is correct |
21 |
Correct |
34 ms |
7140 KB |
Output is correct |
22 |
Correct |
33 ms |
6932 KB |
Output is correct |
23 |
Correct |
48 ms |
6832 KB |
Output is correct |
24 |
Correct |
134 ms |
7416 KB |
Output is correct |
25 |
Correct |
1061 ms |
15412 KB |
Output is correct |
26 |
Correct |
1091 ms |
15168 KB |
Output is correct |
27 |
Correct |
1004 ms |
14712 KB |
Output is correct |
28 |
Correct |
966 ms |
14900 KB |
Output is correct |
29 |
Correct |
932 ms |
14580 KB |
Output is correct |
30 |
Correct |
611 ms |
13876 KB |
Output is correct |
31 |
Correct |
508 ms |
13256 KB |
Output is correct |
32 |
Correct |
500 ms |
13364 KB |
Output is correct |
33 |
Correct |
84 ms |
1948 KB |
Output is correct |
34 |
Correct |
987 ms |
15508 KB |
Output is correct |
35 |
Correct |
938 ms |
14876 KB |
Output is correct |
36 |
Correct |
1047 ms |
15140 KB |
Output is correct |
37 |
Correct |
988 ms |
14912 KB |
Output is correct |
38 |
Correct |
996 ms |
14900 KB |
Output is correct |
39 |
Correct |
979 ms |
14968 KB |
Output is correct |
40 |
Correct |
635 ms |
14948 KB |
Output is correct |
41 |
Correct |
33 ms |
7984 KB |
Output is correct |
42 |
Correct |
487 ms |
13412 KB |
Output is correct |
43 |
Correct |
478 ms |
15164 KB |
Output is correct |
44 |
Correct |
30 ms |
7836 KB |
Output is correct |
45 |
Correct |
591 ms |
14944 KB |
Output is correct |
46 |
Correct |
517 ms |
15256 KB |
Output is correct |
47 |
Correct |
591 ms |
15484 KB |
Output is correct |
48 |
Correct |
527 ms |
15560 KB |
Output is correct |