Submission #1045771

# Submission time Handle Problem Language Result Execution time Memory
1045771 2024-08-06T07:34:37 Z hirayuu_oj Joker (BOI20_joker) C++17
0 / 100
3 ms 4188 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define rng(i,l,r) for(ll i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll=long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll M,L;
    cin>>M>>L;
    vector<ll> A(M*2+1);
    rep(i,M*2+1) {
        cin>>A[i];
    }
    const ll mx=100000;
    vector<vector<ll>> dp(M+2,vector<ll>(mx+1,-(1LL<<60)));
    dp[M+1][0]=0;
    for(ll i=M; i>0; i--) {
        rep(j,i) {
            ll cnt=0;
            deque<pair<ll,ll>> deq;
            for(ll k=j; k<=mx; k+=i) {
                while(!deq.empty()&&deq.front().first<=dp[i+1][k]-cnt) {
                    deq.pop_front();
                }
                deq.push_front({dp[i+1][k]-cnt,cnt});
                if(deq.back().second<cnt-A[M+i])deq.pop_back();
                dp[i][k]=deq.back().first+cnt;
                cnt++;
            }
        }
    }
    if(L<0) {
        cout<<"impossible\n";
        return 0;
    }
    ll weight=L;
    ll used=A[M];
    ll ans=-(1LL<<60);
    rng(i,1,M+1) {
        ll skip=max(0LL,min(A[M+i],(L-mx+10)/i));
        weight-=skip*i;
        used+=skip;
        A[M+i]-=skip;
        rep(j,A[M+i]) {
            weight-=i;
            if(weight<0)break;
            used++;
            if(weight<=mx) {
                ans=max(ans,used+dp[i+1][weight]);
            }
        }
        if(weight<0)break;
    }
    if(ans<0) {
        cout<<"impossible\n";
    }
    else {
        cout<<ans<<"\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -