This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define sp " "
#define endl "\n"
#define mod 1000000007
#define MAXN 200005
#define MAXM 1000005
#define INF 0x3f
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) for(auto& a: x) cout << a << " "
using namespace std;
typedef long long int lo;
const lo inf = 1000000000000000000;
lo arr[MAXN],pre[MAXN],sz[MAXN];
lo n,m,k;
vector<pair<lo,lo>> v[505];
string s;
vector<lo> wind;
vector<lo> bs;
vector<pair<lo,lo>> ind_kac;
lo ans[MAXN];
void init(){
lo mx = 0;
lo i = 1;
while(i <= m){
if(pre[i] == 0){
i++;
continue;
}
// cout<< pre[i] << sp << i << sp << mx << endl;
mx = 0;
while(i <= m and pre[i] >= 0){
mx = max(mx,pre[i]);
i++;
}
if(mx > 0)
wind.pb(mx);
mx = 0;
while(i <= m and pre[i] <= 0){
mx = min(mx,pre[i]);
i++;
}
if(mx < 0)
wind.pb(mx);
}
// debug(wind);
// cout << endl;
bs.pb(abs(wind[0]));
if(wind[0] > 0)
ind_kac[0] = make_pair(wind[0],0);
else
ind_kac[0] = make_pair(0,abs(wind[0]));
for (int i = 1; i < wind.size(); ++i)
{
ind_kac[i] = ind_kac[i-1];
if(wind[i] < 0)
ind_kac[i].se = max(ind_kac[i].se,abs(wind[i]));
else
ind_kac[i].fi = max(ind_kac[i].fi,wind[i]);
bs.pb(ind_kac[i].fi+ind_kac[i].se);
}
// debug(bs);
}
void solve() {
cin >> n >> m;
ind_kac.assign(n+2,{0,0});
for (int i = 1; i <= n; ++i)
{
cin >> arr[i];
}
vector<lo> v;
pre[0] = 0;
for (int i = 1; i <= m; ++i)
{
lo a;cin >> a;
v.pb(a);
pre[i] = pre[i-1] + a;
}
init();
// debug(wind);
// cout << endl;
// debug(bs);
// cout << endl;
// for(auto p: ind_kac){
// cout << p.fi << sp << p.se << endl;
// }
// cout << endl;
// ans[0] += ind_kac[0].fi;
arr[0] = -inf;
arr[n+1] = inf;
pre[n+1] = 0;
for (int i = 1; i <= n+1; ++i)
{
// cout <<i << "::::::: " << endl;
// for (int j = 1; j <= n; ++j)
// {
// cout << j << ":" << ans[j] << endl;
// }
lo fark = arr[i]-arr[i-1];
lo it = upper_bound(all(bs),fark)-bs.begin();
if(it == 0)
continue;
it--;
// cout << fark << endl;
// cout << "it: " << it << sp << ind_kac[it].fi << sp << ind_kac[it].se << endl;
ans[i-1] += ind_kac[it].fi;
ans[i] += ind_kac[it].se;
lo once = ind_kac[it].fi;
lo sonra = ind_kac[it].se;
lo kalan = fark-once-sonra;
if(it != bs.size()-1){
// cout << "kalan: " << i << sp << kalan << sp<< it+2 << sp << pre[it+2] << endl;
if(wind[it+1] > 0){
ans[i-1] += min(wind[it+1],kalan);
}
else{
ans[i] += min(abs(wind[it+1]),kalan);
}
}
// it++;
// if(pre[it+1] > 0) {
// ans[i-1] += min(pre[it],fark-once-sonra);
// // cout << i-1 << sp << ans[i-1];
// }
// else {
// ans[i] += min(abs(pre[it]),fark-once-sonra);
// }
}
for (int i = 1; i <= n; ++i)
{
cout << ans[i] << endl;
}
}
int main()
{
// cout << fixed << setprecision(12);
// freopen("snowboots.in","r",stdin);
// freopen("snowboots.out","w",stdout);
fast;
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
// cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void init()':
Main.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int i = 1; i < wind.size(); ++i)
| ~~^~~~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:124:15: warning: comparison of integer expressions of different signedness: 'lo' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | if(it != bs.size()-1){
| ~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |