Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define gc c=getchar()
- #define r(x) read(x)
- #define ll long long
- template<typename T>
- inline void read(T&x){
- x=0;T k=1;char gc;
- while(!isdigit(c)){if(c=='-')k=-1;gc;}
- while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
- }
- const int N=1e7+5;
- int n;
- ll c[N];
- inline void insert(int x,ll v){
- for(int i=x;i<=n;i+=(i&-i)){
- c[i]=max(c[i],v);
- }
- }
- inline ll query(int x){
- if(x<=0)return 0;
- ll ret=0;
- for(int i=x;i;i^=(i&-i)){
- ret=max(c[i],ret);
- }
- return ret;
- }
- ll f[N];
- int t[N];
- int a[N];
- vector<int>G[N];
- int main(){
- freopen("fc.in","r",stdin);
- freopen("fc.out","w",stdout);
- r(n);
- for(int i=1;i<=n;++i){
- r(t[i]);
- if(i+t[i]<=n)G[i+t[i]].push_back(i);
- }
- for(int i=1;i<=n;++i){
- r(a[i]);
- for(int j=0;j<G[i].size();++j){
- insert(G[i][j],f[G[i][j]]);
- }
- f[i]=query(i-t[i])+(ll)a[i]*t[i];
- }
- ll ans=0;
- for(int i=1;i<=n;++i){
- ans=max(ans,f[i]);
- }
- printf("%lld\n",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement