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>
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |