This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int S[MAXN];
int N, M, K, A, B, C, T;
int dist(int x) {
int lb = 1, rb = M;
while(lb < rb) {
int mid = (lb + rb + 1) >> 1;
if(S[mid] <= x) lb = mid;
else rb = mid - 1;
}
return (S[lb] - 1) * B + (x - S[lb]) * A;
}
void solve(int tc) {
cin >> N >> M >> K >> A >> B >> C >> T;
for(int i=1; i<=M; i++)cin >> S[i];
vector<int> v;
int ans = 0;
vector<int> st, en;
for(int i=1; i<M; i++) {
queue<int> r;
int lb = S[i] + 1, rb = S[i+1] - 1;
while(lb < rb) {
int mid = (lb + rb) >> 1;
if(dist(mid) <= T) lb = mid + 1;
else rb = mid;
}
if(lb > rb) continue;
if(dist(lb) <= T) {
ans += lb - S[i];
v.push_back(-1);
}
else {
ans += (lb - 1) - S[i];
v.push_back(lb);
}
st.push_back(S[i]);
en.push_back(S[i+1]);
}
for(int i=1; i<=K-M; i++) {
vector<pair<int, int> > w;
for(int j=0; j<v.size(); j++) {
if(v[j] == -1) continue;
int val = en[j] - v[j];
int fidi = dist(v[j]) - (v[j] - st[j]) * (A - C);
int runs;
if(T < fidi) runs = 0;
else runs = (T - fidi) / A + 1;
val = min(val, runs);
w.push_back({val, j});
}
if(w.empty()) break;
sort(w.begin(), w.end());
reverse(w.begin(), w.end());
int idx = w[0].second;
int ono = v[idx];
int lb = v[idx], rb = en[idx] - 1;
while(lb < rb) {
int mid = (lb + rb) >> 1;
if(dist(mid) - (ono - st[idx]) * (A - C) <= T) {
lb = mid + 1;
}
else {
rb = mid;
}
}
if(dist(lb) - (ono - st[idx]) * (A - C) <= T) {
ans += lb - v[idx] + 1;
v[idx] = -1;
}
else {
ans += lb - v[idx];
v[idx] = lb;
}
}
for(int i=2; i<=M; i++) {
if(dist(S[i]) <= T) ans++;
}
cout << ans << "\n";
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
Compilation message (stderr)
semiexpress.cpp: In function 'void solve(long long int)':
semiexpress.cpp:49:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int j=0; j<v.size(); j++) {
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |