Problem:
Semiexpress
The JOI Railways is the only railway company in the Kingdom of JOI. There are $N$ stations numbered from $1$ to $N$ along a railway. Currently, two kinds of trains are operated; one is express and the other one is local.
A local train stops at every station. For each $i$ ($1 \leq i < N$), by a local train, it takes $A$ minutes from the station $i$ to the station ($i + 1$).
An express train stops only at the stations $S_1, S_2, ..., S_M$ ($1 = S_1 < S_2 < ... < S_M = N$). For each $i$ ($1 \leq i < N$), by an express train, it takes $B$ minutes from the station $i$ to the station ($i + 1$).
The JOI Railways plans to operate another kind of trains called "semiexpress." For each $i$ ($1 \leq i < N$), by a semiexpress train, it takes $C$ minutes from the station $i$ to the station ($i + 1$). The stops of semiexpress trains are not yet determined. But they must satisfy the following conditions:
Semiexpress trains must stop at every station where express trains stop.
Semiexpress trains must stop at $K$ stations exactly.
The JOI Railways wants to maximize the number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes. The JOI Railways plans to determine the stops of semiexpress trains so that this number is maximized. We do not count the standing time of trains.
When we travel from the station 1 to another station, we can take trains only to the direction where the numbers of stations increase. If several kinds of trains stop at the station $i$ ($2 \leq i \leq N - 1$), you can transfer between any trains which stop at that station.
When the stops of semiexpress trains are determined appropriately, what is the maximum number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes?
Task
Given the number of stations of the JOI Railways, the stops of express trains, the speeds of the trains, and maximum travel time, write a program which calculates the maximum number of stations which satisfy the condition on the travel time.
Input
Read the following data from the standard input.
The first line of input contains three space separated integers $N$, $M$, $K$. This means there are $N$ stations of the JOI Railways, an express train stops at $M$ stations, and a semiexpress train stops at $K$ stations,
The second line of input contains three space separated integers $A$, $B$, $C$. This means it takes $A$, $B$, $C$ minutes by a local, express, semiexpress train to travel from a station to the next station, respectively.
>li> The third line of input contains an integer $T$. This means the JOI Railways wants to maximize the number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes.
The $i$-th line ($1 \leq i \leq M$) of the following $M$ lines contains an integer $S_i$. This means an express train stops at the station $S_i$.
Output
Write one line to the standard output. The output contains the maximum number of stati
...(truncated)

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

const int MAX = 3000;

int n, m, k;
ll a, b, c, t;
int s[MAX];

int arr[3000 * 3000], p = 0;

int calc(int l, int r) {
    int res = 0;
    ll temp = b * l;
    int idx = l, cnt = 0;
    while (idx < r) {
        ll rem = t - temp;
        if (rem < 0) break;
        rem /= a;
        ll nxt = idx + rem + 1;
        nxt = min((ll)r, nxt);
        if (idx == l) res = nxt - idx;
        else arr[p++] = nxt - idx;
        temp += c * (nxt - idx);
        idx = nxt;
        cnt++;
        if (cnt > k - m) break;
    }
    return res;
}

int go() {
    int res = b * s[m - 1] <= t ? 1 : 0;
    for (int i = 0; i < m - 1; ++i) {
        res += calc(s[i], s[i + 1]);
    }
    sort(arr, arr + p);
    reverse(arr, arr + p);
    for (int i = 0; i < k - m; ++i) {
        res += arr[i];
    }
    return res - 1;
}

void read() {
    cin >> n >> m >> k;
    cin >> a >> b >> c >> t;
    
    for (int i = 0; i < m; ++i) {
        cin >> s[i];
        s[i]--;  // adjusting the input by -1 as in the original
    }
}

int main() {
    read();
    int res = go();
    cout << res << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4752
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int int64;

int main() {
    int64 N, M, K, A, B, C, T;
    cin >> N >> M >> K;
    cin >> A >> B >> C;
    cin >> T;

    vector<int64> S(M + 1);
    for (int i = 0; i < M; ++i) {
        cin >> S[i];
    }
    S[M] = N + 1;
    K -= M;

    int64 ret = -1;
    vector<int64> vs;

    for (int i = 0; i < M; ++i) {
        int64 rest = T - (S[i] - 1) * B;
        if (rest < 0) break;
        int64 pv = S[i], reach = min(S[i + 1], pv + rest / A + 1);
        ret += reach - S[i];
        for (int j = 0; j < K && reach < S[i + 1]; ++j) {
            rest -= (reach - pv) * C;
            if (rest < 0) break;
            pv = reach;
            reach = min(S[i + 1], pv + rest / A + 1);
            vs.push_back(reach - pv);
        }
    }

    sort(vs.rbegin(), vs.rend());
    for (int i = 0; i < min(K, (int64)vs.size()); ++i) {
        ret += vs[i];
    }

    cout << ret << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 8240
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, M, K, A, B, C, T, ans = -1;
    cin >> N >> M >> K >> A >> B >> C >> T;
    K -= M;
    vector<ll> S(M), add;
    for(auto &&v:S)cin >> v;
    auto f = [&](ll s, ll t){
        ll st = (s - 1) * B, pos = s;
        for(int i = 0; i <= K && pos < t; i++){
            ll at = st + C * (pos - s);
            if(at > T)return;
            ll inc = (T - at) / A + 1;
            ll nxt = min(t, pos + inc);
            if(i == 0)ans += nxt - pos;
            else add.push_back(nxt - pos);
            pos = nxt;
        }
    };
    S.push_back(N + 1);
    for(int i = 0; i < M; i++){
        f(S[i], S[i + 1]);
    }
    sort(add.rbegin(), add.rend());
    for(int i = 0; i < K && i < add.size(); i++)ans += add[i];
    cout << ans << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 8532
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int n, m, k;
ll a, b, c;
ll t;
struct sexpress {
    int x;
    ll arrival_time;
    bool operator<(const sexpress& s) const {
        return x < s.x;
    }
    sexpress min_unreachable(int next_x) {
        ll num_reachable = 1 + (t - arrival_time) / a;
        int min_unreachable = min(x + num_reachable, ll(next_x));
        ll t_to_min_unreachable = arrival_time + (min_unreachable - x) * c;
        return {min_unreachable, t_to_min_unreachable};
    }
    int gain(int next_x) {
        return min_unreachable(next_x).x - x;
    }
};
struct candidate_loc {
    sexpress s;
    int gain;
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k;
    cin >> a >> b >> c;
    cin >> t;
    vector<int> express(m);
    cin >> express;
    vector<sexpress> semi_express;
    for(int x : express) {
        semi_express.push_back({x, (x - 1) * b});
    }
    semi_express.push_back({n + 1, lim<ll>::max()});
    while(semi_express.size() < k + 1) {
        vector<candidate_loc> candidate_locs;
        for(int i = 0; i < semi_express.size() - 1; i++) {
            auto [x, arrival_time] = semi_express[i];
            if(arrival_time <= t) {
                sexpress candidate_semi = semi_express[i].min_unreachable(semi_express[i + 1].x);
                if(candidate_semi.x < semi_express[i + 1].x and candidate_semi.arrival_time <= t) {
                    candidate_locs.push_back({candidate_semi, candidate_semi.gain(semi_express[i + 1].x)});
                }
            }
        }
        if(candidate_locs.empty()) {
            break;
        }
        candidate_loc best_location = *max_element(candidate_locs.begin(), candidate_locs.end(), [&](const candidate_loc& x, const candidate_loc& y) {
            return x.gain < y.gain;
        });
        semi_express.push_back(best_location.s);
        sort(semi_express.begin(), semi_express.end());
    }
    int ans = 0;
    for(int i = 0; i < semi_express.size() - 1; i++) {
        if(semi_express[i].arrival_time <= t) {
            ans += semi_express[i].gain(semi_express[i + 1].x);
        }
    }
    cout << ans - 1 << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3496
final_rank: 11

code_snippet: #include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
  long long N, M, K;
  cin >> N >> M >> K;
  long long A, B, C, T;
  cin >> A >> B >> C >> T;
  vector<long long> S(M);
  for(int i = 0; i < M; ++i) cin >> S[i], --S[i];
  S.push_back(N);
  K -= M;
  vector<long long> D;
  long long b = 0;
  for(int i = 0; i < M; ++i){
    long long s = S[i]*B, l = S[i];
    long long d = T - s;
    if(d < 0) break;
    long long r = l + d/A;
    r = min(r,S[i+1]-1);
    b += r - l + 1;
    // printf("i, l, r = %lld, %lld, %lld\n",i,l,r);
    l = r+1;
    for(int j = 0; j < K; ++j){
      if(l >= S[i+1]) break;
      long long t = s + (l-S[i])*C, d = T - t;
      if(d < 0) break;
      r = l + d/A;
      r = min(r,S[i+1]-1);
      long long c = r - l + 1;
      // printf("i, j, l, r = %lld, %lld, %lld, %lld\n",i,j,l,r);
      D.push_back(c);
      l = r + 1;
    }
  }
  sort(D.rbegin(), D.rend());
  long long ans = b;

  for(int i = 0; i < min(K,(long long)D.size()); ++i)
    ans += D[i];
  cout << ans-1 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 6968
final_rank: 4

code_snippet: #include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;

ll kyukou[3005];// map<ll, ll> cost;
signed main() {
	ll n, m, k; cin >> n >> m >> k;
	ll a, b, c; cin >> a >> b >> c;
	ll t; cin >> t;
	rep(i, m) { cin >> kyukou[i]; }
	kyukou[m] = n + 1;
	vector<ll> v;
	ll ans = 0;
	rep(i, m) {
		if ((kyukou[i] - 1) * b > t) { break; }
		ll next = kyukou[i] + (t - ((kyukou[i] - 1) * b)) / a + 1;
		ans += min(next, kyukou[i + 1]) - kyukou[i];
		rep(j, k) {
			//もし急行電車が次止まる駅を越したらbreak
			if (next >= kyukou[i + 1]) { break; }
			//もし間に合うなら価値をvに
			ll cost = ((kyukou[i] - 1) * b) + ((next - kyukou[i]) * c);
			ll cango = (t - cost) / a + 1;
			if (cost <= t) {
				v.push_back(min(cango, kyukou[i + 1] - next));
			}
			next = next + cango;
		}
	}
	sort(all(v)); reverse(all(v));
	rep(i, min((ll)v.size(), k - m)) {
		ans += v[i];
	}
	cout << ans - 1 << endl;
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 35868
final_rank: 14

code_snippet: #include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
#define PB push_back
constexpr int kN = int(3E3 + 10);
typedef long long int ll;
ll s[kN];
ll cal(ll &from, ll a, ll st, ll t, ll to) {
	//printf("cal(%lld, %lld, %lld, %lld, %lld)", from, a, st, t, to);
	ll ans = 0;
	if (from + (t - st) / a < to) {
		from += (t - st) / a + 1;
		ans = (t - st) / a + 1;
		//printf("(a)");
	}
	else {
		//printf("(b)");
		ans = to - from;
		from = to;
	}
	//printf(" = %lld\n", ans);
	return ans;
}
int main() {
	ll n, a, b, c, t, m, k, ans = 0, now, lst, cnt;
	vector<ll> v;
	scanf("%lld%lld%lld%lld%lld%lld%lld", &n, &m, &k, &a, &b, &c, &t);
	k -= m;
	for (int i = 1; i <= m; i++) scanf("%lld", &s[i]);
	m++;
	s[m] = n + 1;
	for (int i = 1; i < m; i++) if (b * (s[i] - 1) <= t) {
		lst = s[i];
		ans += cal(s[i], a, b * (s[i] - 1), t, s[i + 1]);
		now = b * (lst - 1) + c * (s[i] - lst);
		cnt = k;
		while (s[i] < s[i + 1] && now <= t && cnt--) {
			lst = s[i];
			v.PB(cal(s[i], a, now, t, s[i + 1]));
			now += c * (s[i] - lst);
		}
	} else break;
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	v.resize(k);
	//printf("v :"); for (int i = 0; i < k; i++) printf(" %lld", i); printf("\n");
	for (int i = 0; i < k; i++) if (v[i] > 0) ans += v[i];
	printf("%lld\n", ans - 1);
}
accuracy: 1
time_ms: 10
memory_kb: 6504
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};


bool solve(){
    ll N, M, K, A, B, C, T;
    cin >> N >> M >> K >> A >> B >> C >> T;
    vector<ll> s(M);
    for(int i=0;i<M;i++){
        cin >> s[i];
        s[i]--;
    }
    ll ans = 0;
    vector<ll> ls;
    for(ll i=0;i<M-1;i++){
        if(B*s[i] > T) break;
        ll r = T-B*s[i], j = s[i], cnt, k = 0;
        cnt = min(r/A+1, s[i+1]-j);
        ans += cnt;
        j += cnt;
        r -= C*cnt;
        while(j < s[i+1] && r >= 0 && k <= K-M){
            cnt = min(r/A+1, s[i+1]-j);
            ls.emplace_back(cnt);
            j += cnt;
            r -= C*cnt;
            k++;
        }
    }
    ans--;  // 駅1
    if(B*(N-1)<=T) ans++;  // 駅N
    sort(ls.rbegin(), ls.rend());
    for(int i=0;i<min(K-M,ll(ls.size()));i++){
        ans += ls[i];
    }
    cout << ans << endl;
    return true;
}

int main(){
    solve();
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7076
final_rank: 6

code_snippet: #include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld=long double;
ld eps=1e-9;

struct Edge {
	int from;
	int to;
	long long int val;
};

struct Status {
	int now;
	int hot;
	int rest;
	long long int cost;
};
bool operator<(const Status&l, const Status&r) {
	return l.cost>r.cost;
}

void add_edge(vector<vector<Edge>>&graph,int a, int b, int c) {
	graph[a].push_back(Edge{ a,b,c });
	graph[b].push_back(Edge{ b,a,c });
}

long long int value(const long long int sa, const long long int S, const long long int T) {
	if (sa > 0) {
		return - sa*S;
	}
	else {
		return - sa*T;
	}
}

int main() {
	long long int N;
	int M,K;cin>>N>>M>>K;K-=M;
	long long int A,B,C;cin>>A>>B>>C;
	long long int T;cin>>T;
	vector<long long int>Ss(M);
	for (int i = 0; i < M; ++i) {
		cin>>Ss[i];Ss[i]--;
	}

	long long int ans=0;
	vector<long long int>v;
	for (int i = 0; i < M; ++i) {
		long long int exp_time=B*Ss[i];
		if (exp_time > T) {

		}
		else {
			if(i!=0)ans++;
			if(i==M-1)continue;
			long long int rest_normal = Ss[i + 1] - Ss[i] - 1;
			long long int rest_time=T-exp_time;

			long long int normal_num=min(rest_normal,rest_time/A);

			ans+=normal_num;

			rest_normal-=normal_num;

			long long int semi_point=Ss[i]+normal_num+1;
			int x=K;
			while (rest_normal) {
				x--;
				if(x<0)break;
				long long int semi_time=exp_time+C*(semi_point-Ss[i]);
				if (semi_time > T) {
					break;
				}
				else {
					long long int nans=0;
					long long int rest_time=T-semi_time;
					long long int anormal_num=min(rest_normal,1+rest_time/A);

					nans=anormal_num;
					v.push_back(nans);

					rest_normal-=anormal_num;
					semi_point+=nans;
				}
			}
		}
	}
	sort(v.begin(),v.end(),greater<long long int>());
	long long int plus=0;
	if(v.size()<K)plus=accumulate(v.begin(),v.end(),0ll);
	else plus=accumulate(v.begin(),v.begin()+K,0ll);
	cout<<ans+plus<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7068
final_rank: 5

code_snippet: // 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 30;
const ll MOD = 1000000007LL;

int N, M, K, A, B, C, T;
int pos[3010];

// dp, 区間 i に j 個おいたらどれだけ稼げるか
int dp[3010][3010], pre[3010][3010];

int get_time(int cur, int span) {
    return (cur - 1) * span;
}

int get_pos(int cur_time, int span) {
    return cur_time / span;
}

int get_bound(int cur_time, int cur_pos, int span, int lim) {
    int ub = INF, lb = -1;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if(cur_time + span * mid > lim) ub = mid;
        else lb = mid;
    }

    // fprintf(stderr, "cur_time = %lld, cur_pos = %lld, lb = %lld\n", cur_time, cur_pos, lb);
    return cur_pos + lb;
}

signed main() {
    cin >> N >> M >> K;
    cin >> A >> B >> C;
    cin >> T;
    for(int i=0; i<M; i++) {
        cin >> pos[i];
    }

    fill(dp[0], dp[3010], -1);
    dp[0][0] = 0;

    int rest = K - M;
    for(int i=0; i<M-1; i++) {
        // pre の計算
        int cur_pos = pos[i];
        for(int j=0; j<=rest; j++) {
            // cur_pos から見て、ギリギリ普通列車で行けるところ
            int cur_time = get_time(pos[i], B) + (cur_pos - pos[i]) * C;
            int posA = cur_pos;
            if(cur_time <= T) {
                posA = get_bound(cur_time, cur_pos, A, T);
                // fprintf(stderr, "time = %lld, i = %lld, j = %lld, cur_pos = %lld, posA = %lld\n", cur_time, i, j, cur_pos, posA);
            
                // ギリギリ行けないところにおいてみる
                int reach_tail = (posA != pos[i+1] and get_time(pos[i+1], B) <= T);
                pre[i][j] = min(pos[i+1] - pos[i], posA - pos[i] + reach_tail);
                cur_pos = posA + 1;
            }
            else {
                pre[i][j] = (j == 0 ? 0 : pre[i][j-1]);
            }
            // fprintf(stderr, "pre[%lld][%lld] = %lld\n", i, j, pre[i][j]);
        }

        // (lb, ub] の間に j 個おいたとして、最大何個カバーできるか？
        for(int j=0; j<=rest; j++) {
            for(int k=0; k<=j; k++) {
                if(dp[i][j-k] < 0) continue;
                if(pre[i][k] == 0) break;
                chmax(dp[i+1][j], dp[i][j-k] + pre[i][k]);
            }
        }
    }
    cout << dp[M-1][rest] << endl;
    return 0;
}
accuracy: 0.05555555555555555
time_ms: 10
memory_kb: 73892
final_rank: 20

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> M >> K;
	long long int a, b, c;
	cin >> a >> b >> c;
	cin >> R;
	vector<long long int>v(M);
	for (auto &i : v)cin >> i;
	int ans = 0;
	if ((N - 1)*b <= R)ans++;
	vector<vector<int>>dp(M, vector<int>(K - M + 1));
	for (int i = 0; i < M - 1; i++) {
		long long int r = v[i] - 1;
		long long int t = R - (v[i] - 1)*b;
	//	cout << "t " << t << endl;
		if (t >= 0) {
			r = max(r, v[i] + t / a);
			r = min(r, v[i + 1] - 1);
		}
		ans += max((long long int)0,r - v[i] + 1);
	//	cout << i << " " << ans << endl;
		long long int rbox = r;
		for (int j = 0; j <= K - M; j++)dp[i + 1][j] = dp[i][j];
		for (int j = 1; j <= K - M; j++) {
			t = R - (v[i] - 1)*b - ((rbox + 1) - v[i])*c;
		//	cout << "t " << t << endl;
			if (t >= 0) {
				rbox = max(rbox, rbox + 1 + t / a);
				rbox = min(rbox, v[i + 1] - 1);
				//	cout << i << " " << j << " " << rbox << endl;
				for (int k = K - M; k >= j; k--) {
					dp[i + 1][k] = max(dp[i + 1][k], dp[i][k - j] + (int)(rbox - r));
				}
			}
		}
	}
//	for (int i = 0; i < M; i++) {
//		for (int j = 0; j <= K - M; j++) {
//			cout << i << " " << j << " " << dp[i][j] << endl;
//		}
//	}
	ans--;
//	cout << ans << endl;
	cout << dp.back().back() + ans << endl;
	return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 8236
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ll locs, locc, semc, expc, target;
    int exps, sems;
    scanf("%lld%d%d%lld%lld%lld%lld", &locs, &exps, &sems, &locc, &expc, &semc, &target);
    vector<ll> expa(exps + 1);
    for (int i = 0; i < exps; i++) {
        scanf("%lld", &expa[i]);
    }
    assert(expa[exps - 1] == locs);
    expa[exps] = locs + 1;
    vector<ll> pieces;
    ll pre = -1;
    for (int i = 0; i < exps; i++) {
        // expa[i], expa[i + 1]
        ll ctarget = target - (expa[i] - expa[0]) * expc;
        ll cremain = expa[i + 1] - expa[i];
        // ensure 
        for (int add = 0; add <= sems - exps; add++) {
            ll L = 0, R = cremain + 1;
            while (R - L > 1) {
                ll M = L + R >> 1;
                ((M - 1) * locc <= ctarget ? L : R) = M;
            }
            if (add) {
                pieces.push_back(L);
            } else {
                pre += L;
            }
            ctarget -= L * semc;
            cremain -= L;
        }
        sort(pieces.begin(), pieces.end());
        if (pieces.size() > sems - exps) pieces.erase(pieces.begin(), pieces.end() - (sems - exps));
    }
    printf("%lld\n", pre + accumulate(pieces.begin(), pieces.end(), 0));
}
accuracy: 1
time_ms: 70
memory_kb: 3372
final_rank: 10

code_snippet: #include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#define INF 1000000000000000
using namespace std;
typedef long long ll;

vector<ll> valueChoices(ll width, ll startT, ll abortT, ll a, ll c, ll k) {
	vector<ll> ans(k + 1, 0);
	int lrs = 0;
	ll margin = abortT - startT;
	ll fus, tc;
	// printf("width %lld with start %lld abort %lld\n", width, startT, abortT);
	for (int tc = 0; tc <= k && margin >= 0; ++tc) {
		//printf("iter %d\n", tc);
		ll statReached = margin/a;
		ll fus = lrs + statReached + 1;
		//printf("fus %lld\n", fus);
		ans[tc] = min(width, fus) - lrs - (tc == 0);
	//	printf("with %d stations: %lld\n", tc, ans[tc]);
		if (fus >= width) {
			break;
		} else {
			margin = abortT - (fus * c) - startT;
			lrs = fus;
		}
	}
	return ans;
}

int main() {
	ll n, m, k; scanf("%lld %lld %lld", &n, &m, &k);
	ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
	ll t; scanf("%lld", &t);
	vector<ll> stops(m, 0);
	for (int i = 0; i < m; ++i) {
		scanf("%lld", &stops[i]);
	}
	vector<ll> widths(m - 1, 0);
	for (int i = 0; i < m - 1; ++i) {
		widths[i] = stops[i+1] - stops[i];
	}
	vector<ll> takeAns;
	ll free = 0;
	takeAns.reserve(k*k);
	for (int i = 0; i < m - 1; ++i) {
		vector<ll> tAns = valueChoices(widths[i], (stops[i] - 1) * b, t, a, c, k);
		for (int j = 1; j < (int)tAns.size(); ++j) {
			takeAns.push_back(tAns[j]);
		}
		free += tAns[0];
	}
	sort(takeAns.begin(), takeAns.end());
	reverse(takeAns.begin(), takeAns.end());
	int wc = 0;
	for (int i = 0; i < min(k - m, (ll)takeAns.size()); ++i) {
		wc += takeAns[i];
	}
	for (int i = 1; i < m; ++i) {
		if (b * (stops[i] - 1) <= t) {
			++wc;
		}
	}
	printf("%lld\n", wc + free);
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 33492
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
long long int stationnum, expressnum, semiexpressnum;
long long int localexptime, exptime, semiexptime;
long long int t;
vector <long long int> mustvisit;
set <long long int> semiexpress;
long long int dps[7001];
bool hasloc(int loc) {
	int s = 0;
	int e = mustvisit.size() - 1;
	while (s <= e) {
		int m = (s + e) / 2;
		if (mustvisit[m] > loc)
			e = m - 1;
		else if (mustvisit[m] < loc)
			s = m + 1;
		else {
			return true;
		}
	}
	return false;
}

/*int bet(int loc1, int loc2) {
	int jumps = 0;
	if (hasloc(loc1))
		jumps--;
	if (hasloc(loc2))
		jumps--;
	//cout << loc1 << ' ' << loc2 << ' ' << "JUMPS " << jumps << '\n';
	int s = 0;
	int e = mustvisit.size() - 1;
	int lowrange = -1;
	int highrange = -1;
	while (s <= e) {
		int m = (s + e) / 2;
		if (mustvisit[m] >= loc1) {
			e = m - 1;
			lowrange = m;
		}
		else if (mustvisit[m] < loc1)
			s = m + 1;
	}
	s = 0;
	e = mustvisit.size() - 1;
	while (s <= e) {
		int m = (s + e) / 2;
		if (mustvisit[m] > loc2) {
			e = m - 1;
		}
		else if (mustvisit[m] <= loc2) {
			s = m + 1;
			highrange = m;
		}
	}
	//cout << "RANGE " << loc1 << ' ' << loc2 << ' ' << lowrange << ' ' << highrange << '\n';
	return jumps + 1 + (highrange - lowrange + 1);
}*/
long long int dp(int loc) {
	if (loc == 1)
		return 0;
	if (dps[loc] == -1) {
		dps[loc] = dp(loc - 1) + localexptime;
		for (int i = loc - 1; i > 0; i--) {
			if (hasloc(i) && hasloc(loc)) {
				dps[loc] = min(dp(i) + min(exptime, semiexptime) * (loc - i), dps[loc]);
			}
			else if ((semiexpress.find(i) != semiexpress.end() && semiexpress.find(loc) != semiexpress.end()) && semiexpressnum - expressnum >= 1) {
				dps[loc] = min(dp(i) + semiexptime * (loc - i), dps[loc]);
			}
			//cout << loc << ' ' << dps[loc] << '\n';
		}
	}
	return dps[loc];
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	for (int i = 0; i <= 300; i++) {
		dps[i] = -1;
	}
	cin >> stationnum >> expressnum >> semiexpressnum;
	cin >> localexptime >> exptime >> semiexptime;
	cin >> t;
	mustvisit.resize(expressnum);
	for (int i = 0; i < expressnum; i++) {
		cin >> mustvisit[i];
		semiexpress.insert(mustvisit[i]);
	}	
	int maxans = 0;
	for (int i = 1; i <= stationnum; i++) {
		for (int j = i + 1; j <= stationnum; j++) {
			int ans = 0;
			if (!hasloc(i) && !hasloc(j)) {
				semiexpress.insert(i);
				semiexpress.insert(j);
				for (int k = 0; k <= stationnum; k++) {
					dps[k] = -1;
				}
				dp(stationnum);
				semiexpress.erase(j);
				semiexpress.erase(i);
				for (int k = 2; k <= stationnum; k++) {
					if (dps[k] <= t)
						ans++;
					}
				if (ans > maxans) {
					maxans = ans;
				}
			}
		}
	}
	cout << maxans << '\n';
}
accuracy: 0.08333333333333333
time_ms: 130
memory_kb: 3136
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
long long int stationnum, expressnum, semiexpressnum;
long long int localexptime, exptime, semiexptime;
long long int t;
vector <long long int> mustvisit;
set <long long int> semiexpress;
long long int dps[7001];
bool hasloc(int loc) {
	int s = 0;
	int e = mustvisit.size() - 1;
	while (s <= e) {
		int m = (s + e) / 2;
		if (mustvisit[m] > loc)
			e = m - 1;
		else if (mustvisit[m] < loc)
			s = m + 1;
		else {
			return true;
		}
	}
	return false;
}

/*int bet(int loc1, int loc2) {
	int jumps = 0;
	if (hasloc(loc1))
		jumps--;
	if (hasloc(loc2))
		jumps--;
	//cout << loc1 << ' ' << loc2 << ' ' << "JUMPS " << jumps << '\n';
	int s = 0;
	int e = mustvisit.size() - 1;
	int lowrange = -1;
	int highrange = -1;
	while (s <= e) {
		int m = (s + e) / 2;
		if (mustvisit[m] >= loc1) {
			e = m - 1;
			lowrange = m;
		}
		else if (mustvisit[m] < loc1)
			s = m + 1;
	}
	s = 0;
	e = mustvisit.size() - 1;
	while (s <= e) {
		int m = (s + e) / 2;
		if (mustvisit[m] > loc2) {
			e = m - 1;
		}
		else if (mustvisit[m] <= loc2) {
			s = m + 1;
			highrange = m;
		}
	}
	//cout << "RANGE " << loc1 << ' ' << loc2 << ' ' << lowrange << ' ' << highrange << '\n';
	return jumps + 1 + (highrange - lowrange + 1);
}*/
long long int dp(int loc) {
	if (loc == 1)
		return 0;
	if (dps[loc] == -1) {
		dps[loc] = dp(loc - 1) + localexptime;
		for (int i = loc - 1; i > 0; i--) {
			if (hasloc(i) && hasloc(loc)) {
				dps[loc] = min(dp(i) + min(exptime, semiexptime) * (loc - i), dps[loc]);
			}
			else if ((semiexpress.find(i) != semiexpress.end() && semiexpress.find(loc) != semiexpress.end()) && semiexpressnum - expressnum >= 1) {
				dps[loc] = min(dp(i) + semiexptime * (loc - i), dps[loc]);
			}
			//cout << loc << ' ' << dps[loc] << '\n';
		}
	}
	return dps[loc];
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	for (int i = 0; i <= 300; i++) {
		dps[i] = -1;
	}
	cin >> stationnum >> expressnum >> semiexpressnum;
	cin >> localexptime >> exptime >> semiexptime;
	cin >> t;
	mustvisit.resize(expressnum);
	for (int i = 0; i < expressnum; i++) {
		cin >> mustvisit[i];
		semiexpress.insert(mustvisit[i]);
	}	
	int maxans = 0;
	for (int i = 1; i <= stationnum; i++) {
		for (int j = i + 1; j <= stationnum; j++) {
			int ans = 0;
			if (!hasloc(i) && !hasloc(j)) {
				semiexpress.insert(i);
				semiexpress.insert(j);
				for (int k = 0; k <= stationnum; k++) {
					dps[k] = -1;
				}
				dp(stationnum);
				semiexpress.erase(j);
				semiexpress.erase(i);
				for (int i = 2; i <= stationnum; i++) {
					if (dps[i] <= t)
						ans++;
					}
				maxans = max(maxans, ans);
			}
		}
	}
	cout << maxans << '\n';
}
accuracy: 0.08333333333333333
time_ms: 130
memory_kb: 3208
final_rank: 19

code_snippet: #include <iostream>
#include <cassert>
#include <queue>

typedef long long ll;

ll N, M, K;
ll A, B, C;
ll T;

ll S[3001];
std::priority_queue<int, std::vector<int>, std::greater<int> > pq;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	
	std::cin>>N>>M>>K;
	std::cin>>A>>B>>C;
	std::cin>>T;
	
	for (int i = 0; i < M; ++i)
		std::cin>>S[i];
	
	ll ans = 0;
	for (int i = 0; i < M-1; ++i) {
		ll cur = B * (S[i] - 1);
		ll n = S[i+1] - S[i];
/*		ll step = std::min((T-cur)/A, n);
		ans += step + 1;
		if (step == n)
			continue;
*/		
		int iter = 0;
		while (n > 0 and cur <= T and iter <= 5000) {
			ll step = std::min((T-cur)/A, n-1);
			
			if (iter == 0) {
				ans += 1+step;
			} else {
				pq.push(1+step);
				if (pq.size() > K - M)
					pq.pop();
			}
			cur += C*(step+1);
			n -= step+1;
			
			iter++;
		}
	}
	if (B*(S[M-1]-1) <= T)
		ans++;
	
	while (!pq.empty()) {
		ans += pq.top();
		pq.pop();
	}
	
	std::cout<<ans-1<<"\n";
	
	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3168
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll s[3001];
vector<ll> v;
int main(){
    ll n,m,k,a,b,c,t;
    cin>>n>>m>>k;
    cin>>a>>b>>c>>t;
    rep(i,m){
        cin>>s[i];
        --s[i];
    }
    int r=k-m;
    ll ans=(s[m-1]*b<=t)?1:0;
    rep(i,m-1){
        ll cur=b*s[i];
        if(cur>t) break;
        ll cnt=(t-cur)/a+1;
        ans+=min(s[i+1]-s[i],cnt);
        cur+=(cnt)*c;
        if(cur>t) continue;
        rep(j,r){
            ll cnt2=(t-cur)/a+1;
            ll ss=min(s[i]+cnt+cnt2,s[i+1])-min(s[i]+cnt,s[i+1]);
            v.pb(ss);
            cur+=(cnt2)*c;cnt+=cnt2;
            if(cur>t) break;
        }
    }
    sort(v.rbegin(),v.rend());
    int cnt=0;
    for(auto it:v){
        if(cnt==k-m) break;
        ans+=it;++cnt;
    }
    cout<<ans-1<<endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 19324
final_rank: 12

code_snippet: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
typedef long long ll;
 
ll N,M,K,L,A,B,C,T;
ll esta[3010];//急行駅の番号
 
 
vector<ll> vec;
 
inline ll updiv(ll a,ll b){
	return a%b ? a/b+1 : a/b;
}
 
int main(){
	cin>>N>>M>>K>>A>>B>>C>>T;
 
	for(int i=1;i<=M;i++) cin>>esta[i];
 
	L=K-M;
	ll res=0;
	for(int i=2;i<=M;i++){
		if(B*(esta[i]-1)>T) break;
		res++;
	}
 
	for(int i=1;i<M;i++){
		ll now_t=(esta[i]-1)*B;
		ll now_n=esta[i];
		if(now_t>T) break;
		ll cango=(T-now_t)/A;
		if(now_n+cango>=esta[i+1]-1){
			res+=(esta[i+1]-esta[i]-1);
			continue;
		}
		res+=cango;
 
		for(int j=1;j<=3010;j++){
			if(cango==0&&(T-now_t)<C) break;
			now_t+=C*(cango+1);
			now_n+=cango+1;
			if(now_t>T) break;
			cango=(T-now_t)/A;
			if(now_n+cango>=esta[i+1]-1){
				vec.push_back(esta[i+1]-now_n);
				break;
			}
			vec.push_back(cango+1);
		}
	}
	sort(vec.begin(),vec.end(),greater<ll>());
 
	L=min(L,(ll)vec.size());
	for(int i=0;i<L;i++){
		res+=vec[i];
	}
	cout<<res<<endl;
	return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 68576
final_rank: 17

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 3010

int a,b,c;
ll t;

void calc(int n, int m, ll st_time, int *v){
  ll cc = 0;
  
  int l = 0;
  
  for(int i=0;i<=m && i<=n-1;i++){
    ll sum = st_time + (ll)c*l;

    if(sum <= t){
      cc++;
    }else{
      break;
    }
    
    ll cc2 = (t - sum)/a;

    cc = min(cc + cc2, (ll)n);

    l = cc;
    
    v[i] = cc;
  }
  
}

int dp[SIZE];
int v[SIZE][SIZE] = {};

int main(){
  int n,m,k;
  int s[SIZE];
  
  scanf("%d%d%d",&n,&m,&k);
  
  scanf("%d%d%d%lld",&a,&b,&c,&t);

  for(int i=0;i<m;i++){
    scanf("%d",s+i);
    s[i]--;
  }

  for(int i=0;i<=k;i++){
    dp[i] = -INF-10;
  }
  
  dp[m] = 0;
  
  int ans = 0;

  priority_queue<pair<int,pair<int,int> > > pq;
  
  for(int i=0;i<m-1;i++){

    calc(s[i+1]-s[i], k-m, (ll)b*s[i], v[i]);
    
    pq.push({v[i][1]-v[i][0],{i,1}});
    ans += v[i][0];
  }
  
  for(int i=m;i<k;i++){
    if(pq.top().first < 0) break;
    
    ans += pq.top().first;

    int p = pq.top().second.first;
    int q = pq.top().second.second;

    pq.pop();
    
    pq.push({v[p][q+1]-v[p][q],{p,q+1}});
  }

  if((ll)(n-1)*b <= t) ans++;

  printf("%d\n",ans-1);
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 14100
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
long long A, B, C, N, M, K, T, E[4009], U = 0; vector<long long>V;
int main() {
	cin >> N >> M >> K >> A >> B >> C >> T;
	for (int i = 1; i <= M; i++) cin >> E[i];
	for (int i = 1; i < M; i++) {
		long long rem = T - (E[i] - 1) * B, cx = E[i], cnt = 0; if (rem < 0)continue;
		while (true) {
			long long D = rem / A + 1, F = cx + D; F = min(F, E[i + 1]); D = F - cx;
			if (cnt >= 1)V.push_back(D); else U += D;
			rem -= D*C; cx += D; if (cx >= E[i + 1] || D == 0 || rem < 0LL || cnt > K - M)break; cnt++;
		}
	}
	if ((N - 1)*B <= T)U++;
	sort(V.begin(), V.end(), greater<long long>());
	for (int i = 0; i < min((long long)V.size(), K - M); i++)U += V[i];
	cout << U - 1 << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6960
final_rank: 3