Submission #580925

# Submission time Handle Problem Language Result Execution time Memory
580925 2022-06-22T06:25:49 Z Theo830 Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 464 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define ull unsigned ll
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,q;
    cin>>n>>q;
    vll arr;
    arr.pb(-INF);
    vector<ii>exo;
    f(i,0,n){
        ll a;
        cin>>a;
        arr.pb(a);
    }
    arr.pb(INF);
    f(i,0,n+1){
        exo.pb(ii(arr[i+1] - arr[i],i));
    }
    ll ans[n+1] = {0};
    ll cur = 0;
    ll mini = 0,maxi = 0;
    sort(all(exo));
    reverse(all(exo));
    while(q--){
        ll w;
        cin>>w;
        cur += w;
        maxi = max(maxi,cur);
        mini = min(mini,cur);
        while(exo.back().F <= abs(mini) + maxi){
            ll c = abs(mini) + maxi - exo.back().F;
            ll i = exo.back().S;
            if(maxi == cur){
                ans[i] += maxi - c;
                ans[i+1] += abs(mini);
            }
            else{
                ans[i] += maxi;
                ans[i+1] += abs(mini) - c;
            }
            exo.pop_back();
        }
    }
    while(!exo.empty()){
        ll i = exo.back().S;
        exo.pop_back();
        ans[i] += maxi;
        ans[i+1] += abs(mini);
    }
    f(i,1,n+1){
        cout<<ans[i]<<"\n";
    }
}

# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -