#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2,fma")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
const long long int N = 7e5+20,mod = 1e9+7,inf = 1e9+10,sq = 400;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int n,int k){
int c = 1;
while (k){
if (k&1) c = (1ll*c*n)%mod;
n = (1ll*n*n)%mod;
k >>= 1;
}
return c;
}
int dp[N][2],n,m,k,a,b,c,r[N],pre[N],ig[N],nxt[N];
ll t,ti[N];
bitset<inf> st;
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k >> a >> b >> c >> t;
vector<pair<int,bool>> ve;
ve.reserve(N);
vector<int> imp;
imp.reserve(m);
int lst = 1;
ve.pb({0,0});
rep(i,0,m){
int x;
cin >> x;
ve.pb({x,1});
imp.pb(x);
}
int cnt = 0;
rep(i,0,m){
ll tm = 1ll*b*(imp[i]-1),l = imp[i];
while (tm <= t && (t-tm)/a+l < n && (i < m-1 && (t-tm)/a+l+1 < imp[i+1]) && cnt < k-m+30000){
int p = (t-tm)/a+l+1;
if (st[p]) break;
st[p] = 1;
ve.pb({p,0});
tm += 1ll*(p-l)*c;
l = p;
cnt++;
}
lst = imp[i];
}
sort(ve.begin(),ve.end());
int sz = ve.size()-1;
lst = 1;
cnt = 0;
rep(i,1,sz+1){
ll tm = 1ll*b*(lst-1);
if (tm > t){
pre[i] = pre[i-1]+ve[i].X-ve[i-1].X;
}
else{
int p = (t-tm)/a+lst-ve[i-1].X;
if (p < 0) p = 0;
if (p > ve[i].X-ve[i-1].X){
p = ve[i].X-ve[i-1].X;
}
cnt += p;
pre[i] = pre[i-1]+ve[i].X-ve[i-1].X-p;
if (1ll*b*(ve[i].X-1) <= t && ve[i].Y && p < ve[i].X-ve[i-1].X){
cnt++;
pre[i]--;
}
}
if (ve[i].Y) lst = ve[i].X;
ti[i] = 1ll*b*(lst-1)+1ll*a*(ve[i].X-lst);
dp[i][0] = -inf;
}
lst = 1;
rep(i,1,sz+1){
if (ve[i].Y) lst = ve[i].X;
ll tm = 1ll*b*(lst-1)+1ll*c*(ve[i].X-lst);
if (tm > t) r[i] = ve[i].X-1;
else r[i] = min(1ll*n,(t-tm)/a+ve[i].X);
if (!ve[i].Y) r[i] = min(r[i],*(lower_bound(imp.begin(),imp.end(),ve[i].X))-1);
else r[i] = min(r[i],ve[i].X-1);
}
repr(i,sz,1){
ig[i] = lower_bound(r,r+sz+1,ve[i].X)-r-1;
}
rep(d,1,k+1){
int j = (d&1);
rep(i,1,sz+1){
if (ve[i].Y) dp[i][j] = dp[i-1][1-j];
else dp[i][j] = dp[i-1][j];
if (ti[i] <= t || ve[i].Y || r[i] < ve[i].X){
if (ve[i].Y) lst = ve[i].X;
continue;
}
int ind = ig[i];
ll tm = 1ll*b*(lst-1);
if (tm > t){
dp[i][j] = max(dp[i][j],dp[ind][1-j]+r[i]-ve[i].X+1);
continue;
}
int p = (t-tm)/a+lst;
if (p >= ve[i].X) dp[i][j] = max(dp[i][j],dp[ind][1-j]+r[i]-p);
else dp[i][j] = max(dp[i][j],dp[ind][1-j]+r[i]-ve[i].X+1);
}
}
cout << dp[sz][(k&1)]+cnt-1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
460 KB |
Output is correct |
20 |
Correct |
4 ms |
460 KB |
Output is correct |
21 |
Correct |
206 ms |
1492 KB |
Output is correct |
22 |
Correct |
364 ms |
4044 KB |
Output is correct |
23 |
Correct |
469 ms |
7044 KB |
Output is correct |
24 |
Correct |
279 ms |
8908 KB |
Output is correct |
25 |
Correct |
2 ms |
504 KB |
Output is correct |
26 |
Correct |
5 ms |
484 KB |
Output is correct |
27 |
Correct |
265 ms |
1484 KB |
Output is correct |
28 |
Correct |
273 ms |
1484 KB |
Output is correct |
29 |
Correct |
206 ms |
2124 KB |
Output is correct |
30 |
Correct |
372 ms |
2252 KB |
Output is correct |