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>
const long long N = 3005;
using namespace std;
typedef pair <long long, long long> ii;
typedef pair <ii, long long> iii;
priority_queue <iii> mq;
long long n, m, k, a, b, c, s[N], ans, T;
long long cal(long long pos, long long pre){
long long val = T - (s[pre]-1)*b - (pos-s[pre])*c;
if (val < 0) return 0;
return 1 + val/a;
}
int main(){
cin >> n >> m >> k >> a >> b >> c >> T; k-=m;
for (long long i = 1; i <= m; i++) cin >> s[i];
if ((n-1)*b > T) ans = -1;
for (long long i = 1; i < m; i++){
long long pos = s[i], pre = i, val = cal(pos, pre);
if (pos + val > s[pre+1]) val = s[pre+1]-pos;
ans += val; pos += val; if (pos == s[pre+1]) continue;
val = cal(pos, pre);
if (pos + val > s[pre+1]) val = s[pre+1]-pos;
mq.push(iii(ii(val, pos), pre));
}
for (long long i = 1; i <= k && mq.size(); i++){
iii z = mq.top(); mq.pop();
long long pos = z.first.second, val = z.first.first, pre = z.second;
ans += val; pos += val; if (pos == s[pre+1]) continue;
val = cal(pos, pre);
if (pos + val > s[pre+1]) val = s[pre+1] - pos;
mq.push(iii(ii(val, pos), pre));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |