#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
const ll SIZE = 1000, INF = 1e9 * 1e9 + 10;
vector<ll> vec;
#define int ll
ll dpAns[10000][2], dpt[SIZE], good[SIZE];
ll n, m, k, a, b, c;
void add(int curInd, int us, int s) {
for (int i = k; i >= 0; i--) {
if (i - us >= 0) {
dpAns[i][curInd] = max(dpAns[i][curInd], dpAns[i - us][!curInd] + s);
}
}
}
void solve() {
cin >> a >> b >> c;
ll t;
cin >> t;
vec.resize(m);
for (auto &cur : vec) cin >> cur;
good[1] = 1;
ll lastI = -1, curInd = 0;
for (int i = 1; i <= n; i++) {
dpt[i] = dpt[i - 1] + a;
if (vec[lastI + 1] == i) {
good[i] = 1;
if (i == 1) {
dpt[i] = 0;
lastI++;
continue;
}
dpt[i] = min(dpt[i], min(dpt[vec[lastI]] + c * (i - vec[lastI]), dpt[vec[lastI]] + b * (i - vec[lastI])));
lastI++;
}
}
k -= m;
ll ans = 0, added = 0, lastPos = 1, s = 0;
for (int i = 1; i <= n; i++) {
if (dpt[i] <= t) {
ans++;
}
else {
s++;
}
dpt[i] = min(dpt[i], dpt[i - 1] + a);
if (dpt[i] > t) {
added++;
dpt[i] = dpt[lastPos] + c * (i - lastPos);
lastPos = i;
}
if (dpt[i] <= t) {
add(curInd, added, s);
}
if (good[i]) {
lastPos = i;
curInd = !curInd;
for (int j = 0; j <= k; j++) dpAns[j][curInd] = dpAns[j][!curInd];
s = 0;
added = 0;
}
}
s = 0;
for (int i = 0; i <= k; i++) s = max(s, dpAns[i][curInd]);
cout << ans + s - 1;
}
signed main()
{
fastInp;
cin >> n >> m >> k;
if (n <= 310) {
solve();
return 0;
}
cin >> a >> b >> c;
ll t;
cin >> t;
vec.resize(m);
for (auto &cur : vec) cin >> cur;
ll ans = 0;
multiset<ll> addt;
for (int i = 0; i < vec.size(); i++) {
ll lastInd = vec[i], lastIndT = (vec[i] - 1) * b;
while (addt.size() != 0 && addt.size() > k) {
addt.erase(--addt.end());
}
for (int j = 0; j < k; j++) {
if (lastIndT > t) break;
ll l = lastInd, r = n + 1;
if (i < vec.size() - 1 && lastInd >= vec[i + 1]) break;
while (r - l > 1) {
ll mid = (l + r) / 2;
if (lastIndT + (mid - lastInd) * a > t) {
r = mid;
}
else {
l = mid;
}
}
if (l == lastInd) {
if (j != 0) {
addt.insert(-1);
}
else ans++;
l++;
lastIndT += (l - lastInd) * c;
continue;
}
if (i < vec.size() - 1 && l >= vec[i + 1]) {
if (j != 0) {
addt.insert(-(vec[i + 1] - lastInd));
}
else ans += vec[i + 1] - lastInd;
break;
}
l++;
lastIndT += (l - lastInd) * c;
if (j != 0) {
addt.insert(-(l - lastInd));
}
else ans += l - lastInd;
lastInd = l;
}
}
k -= m;
ll s = 0;
while (addt.size() && k) {
k--;
s += abs(*addt.begin());
addt.erase(addt.begin());
}
cout << ans + s - 1;
return 0;
}
/*
10 3 5
10 3 5
30
1
6
10
10 3 5
10 3 5
25
1
6
10
90 10 12
100000 1000 10000
10000
1
10
20
30
40
50
60
70
80
90
12 3 4
10 1 2
30
1
11
12
300 8 16
345678901 123456789 234567890
12345678901
1
10
77
82
137
210
297
300
1000000000 2 3000
1000000000 1 2
1000000000
1
1000000000
*/
Compilation message
semiexpress.cpp: In function 'int main()':
semiexpress.cpp:115:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for (int i = 0; i < vec.size(); i++) {
| ~~^~~~~~~~~~~~
semiexpress.cpp:117:42: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
117 | while (addt.size() != 0 && addt.size() > k) {
| ~~~~~~~~~~~~^~~
semiexpress.cpp:123:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | if (i < vec.size() - 1 && lastInd >= vec[i + 1]) break;
| ~~^~~~~~~~~~~~~~~~
semiexpress.cpp:143:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
143 | if (i < vec.size() - 1 && l >= vec[i + 1]) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
44 ms |
640 KB |
Output is correct |
22 |
Correct |
20 ms |
512 KB |
Output is correct |
23 |
Correct |
144 ms |
644 KB |
Output is correct |
24 |
Correct |
129 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
451 ms |
556 KB |
Output is correct |
28 |
Correct |
589 ms |
632 KB |
Output is correct |
29 |
Correct |
131 ms |
384 KB |
Output is correct |
30 |
Correct |
49 ms |
512 KB |
Output is correct |