Submission #1179656

#TimeUsernameProblemLanguageResultExecution timeMemory
1179656Zbyszek99Semiexpress (JOI17_semiexpress)C++20
100 / 100
0 ms560 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define vl vector<long long>
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //random();
    ll n;
    int m,k;
    cin >> n >> m >> k;
    ll a,b,c;
    cin >> a >> b >> c;
    ll t;
    cin >> t;
    vl S(m);
    rep(i,m) cin >> S[i];
    S.pb(n+1);
    ll ans = -1;
    priority_queue<pair<pll,pll>> q;
    rep(i,m)
    {
        if(b * (S[i]-1)> t) continue;
        ll end_ = min(S[i+1]-1,S[i] + (t-b*(S[i]-1))/a);
        ans += end_ - S[i]+1;
       // cout << i << " " << ans << " ans\n";
        if(end_ != S[i+1]-1 && b*(S[i]-1) + c * (end_ - S[i]+1) <= t)
        {
            ll new_end = min(S[i+1]-1,end_ + 1 + (t-b*(S[i]-1)-c * (end_ - S[i]+1))/a);
            q.push({{new_end-end_,i},{end_+1,b*(S[i]-1)+c*(end_ - S[i]+1)}});
        }
    }
    //cout << ans << " first\n";
    rep(i,k-m)
    {
        if(siz(q) == 0) break;
        pair<pll,pll> to = q.top();
        q.pop();
        ans += to.ff.ff;
        int ind = to.ff.ss;
        ll start = to.ss.ff;
        ll cur_cost = to.ss.ss;
      //  cout << ind << " " << to.ff.ff << " " << start << " " << cur_cost << " xd\n";
        ll nxt = min(S[ind+1]-1,start + (t-cur_cost)/a);
        if(nxt != S[ind+1]-1 && cur_cost + c*(nxt - start+1) <= t)
        {
            ll new_end = min(S[ind+1]-1,nxt+1+(t-cur_cost-c*(nxt-start+1))/a);
            q.push({{new_end-nxt,ind},{nxt+1,cur_cost+c*(nxt-start+1)}});
        }
    }
    cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...