#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e18+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, d[N], a[N], b[N], h[N], dp[N], cnt, top[N], nchain[N], chain, par[N];
vector<pll> adj[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void sol()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++)cin >> a[i];
vector<ll> l, r;
vector<pll> vl, vr;
ll mn = 0, mx = 0;
for(int i = 1; i <= m; i ++)
{
cin >> k;
b[i] = b[i-1] + k;
mn = max(mn, -b[i]);
mx = max(mx, b[i]);
if(vl.empty() || vl.back().fi < mn)
{
vl.pb({mn, mx});
l.pb(mn+mx);
}
if(vr.empty() || vr.back().fi < mx)
{
vr.pb({mx, mn});
r.pb(mn+mx);
}
//cout << mn <<" "<<mx<<'\n';
}
a[0] = -mod ;
a[n+1] = mod;
for(int i = 1; i <= n; i ++)
{
ans = 0;
k = lower_bound(r.begin(), r.end(), a[i+1]-a[i]) - r.begin();
tong = 0;
if(k < vr.size())tong = max(tong, a[i+1]-a[i]-vr[k].se);
if(k)tong = max(tong, vr[k-1].fi);
ans += tong;
//cout << tong <<" ";
k = lower_bound(l.begin(), l.end(), a[i]-a[i-1]) - l.begin();
tong = 0;
if(k < vl.size())tong = max(tong, a[i]-a[i-1]-vl[k].se);
if(k)tong = max(tong, vl[k-1].fi);
//cout << tong <<" ";
ans += tong;
cout << ans << '\n';
}
}
int main()
{
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
5 1
0 1 2
0 2 3
1 3 5
2 4 6
1 1
4 3
*/
Compilation message
Main.cpp: In function 'void sol()':
Main.cpp:59:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | if(k < vr.size())tong = max(tong, a[i+1]-a[i]-vr[k].se);
| ~~^~~~~~~~~~~
Main.cpp:65:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | if(k < vl.size())tong = max(tong, a[i]-a[i-1]-vl[k].se);
| ~~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:77:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | freopen(task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:78:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
4 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5068 KB |
Output is correct |
4 |
Correct |
6 ms |
5164 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
5 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5068 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
5068 KB |
Output is correct |
17 |
Correct |
4 ms |
5068 KB |
Output is correct |
18 |
Correct |
4 ms |
4908 KB |
Output is correct |
19 |
Correct |
4 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
4 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5068 KB |
Output is correct |
4 |
Correct |
6 ms |
5164 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
5 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Correct |
4 ms |
5068 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
5068 KB |
Output is correct |
16 |
Correct |
4 ms |
5068 KB |
Output is correct |
17 |
Correct |
4 ms |
5068 KB |
Output is correct |
18 |
Correct |
4 ms |
4908 KB |
Output is correct |
19 |
Correct |
4 ms |
5068 KB |
Output is correct |
20 |
Correct |
44 ms |
12820 KB |
Output is correct |
21 |
Correct |
40 ms |
12512 KB |
Output is correct |
22 |
Correct |
38 ms |
12244 KB |
Output is correct |
23 |
Correct |
37 ms |
12192 KB |
Output is correct |
24 |
Correct |
49 ms |
12832 KB |
Output is correct |
25 |
Correct |
158 ms |
15376 KB |
Output is correct |
26 |
Correct |
181 ms |
16020 KB |
Output is correct |
27 |
Correct |
152 ms |
15176 KB |
Output is correct |
28 |
Correct |
178 ms |
14748 KB |
Output is correct |
29 |
Correct |
141 ms |
12160 KB |
Output is correct |
30 |
Correct |
96 ms |
8928 KB |
Output is correct |
31 |
Correct |
80 ms |
8464 KB |
Output is correct |
32 |
Correct |
72 ms |
8500 KB |
Output is correct |
33 |
Correct |
16 ms |
5964 KB |
Output is correct |
34 |
Correct |
121 ms |
9860 KB |
Output is correct |
35 |
Correct |
119 ms |
10128 KB |
Output is correct |
36 |
Correct |
158 ms |
15540 KB |
Output is correct |
37 |
Correct |
157 ms |
14028 KB |
Output is correct |
38 |
Correct |
202 ms |
15264 KB |
Output is correct |
39 |
Correct |
150 ms |
14856 KB |
Output is correct |
40 |
Correct |
108 ms |
14748 KB |
Output is correct |
41 |
Correct |
45 ms |
13272 KB |
Output is correct |
42 |
Correct |
72 ms |
11584 KB |
Output is correct |
43 |
Correct |
103 ms |
20640 KB |
Output is correct |
44 |
Correct |
44 ms |
14860 KB |
Output is correct |
45 |
Correct |
93 ms |
18416 KB |
Output is correct |
46 |
Correct |
107 ms |
20768 KB |
Output is correct |
47 |
Correct |
101 ms |
18016 KB |
Output is correct |
48 |
Correct |
120 ms |
22180 KB |
Output is correct |