# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
692548 | guagua0407 | Snowball (JOI21_ho_t2) | C++17 | 1 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
燒雞
燒雞
燒雞 好想進選訓
燒雞
燒雞
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=2e5+5;
ll num[mxn];
ll gap[mxn];
ll ans[mxn];
int main() {_
//setIO("wayne");
int n,q;
cin>>n>>q;
for(int i=0;i<n;i++){
cin>>num[i];
}
for(int i=0;i<n-1;i++){
gap[i]=num[i+1]-num[i];
}
pair<ll,ll> cur={0ll,0ll};
ll pos=0;
vector<pair<ll,ll>> vec;
for(int i=0;i<q;i++){
ll x;
cin>>x;
pos+=x;
cur.f=max(cur.f,pos*-1);
cur.s=max(cur.s,pos);
vec.push_back(cur);
}
vector<ll> sum(q);
for(int i=0;i<q;i++){
sum[i]=vec[i].f+vec[i].s;
}
for(int i=0;i<n-1;i++){
ll gp=gap[i];
int pos=upper_bound(all(sum),gp)-sum.begin()-1;
if(pos==q-1){
ans[i]+=vec[pos].s;
ans[i+1]+=vec[pos].f;
}
else{
if(vec[pos+1].f>vec[pos].f){
ans[i]+=vec[pos].s;
ans[i+1]+=gp-vec[pos].s;
}
else{
ans[i]+=gp-vec[pos].f;
ans[i+1]+=vec[pos].f;
}
}
}
ans[0]+=cur.f;
ans[n-1]+=cur.s;
for(int i=0;i<n;i++){
cout<<ans[i]<<'\n';
}
return 0;
}
//maybe its multiset not set
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |