跳到正文

题解

题解:P15800 [GESP202603 六级] 选数

suihaoxuan0317约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年3月16日
收录
2026年10月5日
更新
2026年11月16日
篇幅
约 1 分钟
题目
P15800

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n;
int a[N],b[N];
long long dp[N],ans;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i)cin>>b[i];
	for(int i=1;i<=n;++i){
		ans=max(ans,dp[i]+a[i]);
		if(i+b[i]<=n)dp[i+b[i]]=max(dp[i+b[i]],dp[i]+a[i]);
		dp[i+1]=max(dp[i+1],dp[i]);
	}
	cout<<ans<<'\n';
	return 0;
}
原文