QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252285 | #4590. Happy Travelling | lam | WA | 2ms | 11812kb | C++14 | 1.4kb | 2023-11-15 17:39:23 | 2023-11-15 17:39:24 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e6 + 5;
int dp[maxn],dp2[maxn];
int f[4*maxn];
int a[maxn],t[maxn];
int n,k,d;
void update(int x, int lx, int rx, int l, int r, int val)
{
if (lx>r||rx<l) return;
if (lx>=l&&rx<=r)
{
f[x]=max(f[x],val);
return;
}
int mid=(lx+rx)/2;
update(2*x,lx,mid,l,r,val);
update(2*x+1,mid+1,rx,l,r,val);
}
int get(int x, int lx, int rx, int idx)
{
if (lx==rx) return f[x];
int mid=(lx+rx)/2;
if (idx<=mid) return max(f[x],get(2*x,lx,mid,idx));
else return max(f[x],get(2*x+1,mid+1,rx,idx));
}
signed main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> k >> d;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int j = 1; j < n; j++) cin >> t[j];
fill_n(dp,n+1,-1e18);
fill_n(dp2,n+1,-1e18);
fill_n(f,4*n+1,-1e18);
update(1,1,n,1,1,0);
int mmax = -1;
for (int i = 1; i <= n; i++)
{
dp[i] = a[i] + get(1,1,n,i);
if (i == n) continue;
int val = max(dp[i], dp2[i]);
mmax = max(mmax, i+t[i]);
if (mmax >= i + k)
{
dp2[i+k] = max(dp2[i+k], val - d);
}
if (mmax > i) update(1,1,n,i+1,min(mmax,i+k-1), val);
}
cout << dp[n] << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11808kb
input:
6 2 1 8 -7 -8 9 0 2 5 3 3 2 1
output:
18
result:
ok single line: '18'
Test #2:
score: 0
Accepted
time: 0ms
memory: 11808kb
input:
8 8 8 10 -5 -5 -5 -5 -5 -5 10 5 2 5 3 2 1 1
output:
15
result:
ok single line: '15'
Test #3:
score: 0
Accepted
time: 2ms
memory: 11812kb
input:
13 2 2 -5 -4 -4 -1 7 -6 -5 -4 -3 -2 -1 5 -7 3 10 9 8 7 6 5 4 3 2 1 1
output:
-9
result:
ok single line: '-9'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 11772kb
input:
2 1 0 -10000 10000 1
output:
-999999999999990000
result:
wrong answer 1st lines differ - expected: '0', found: '-999999999999990000'