C. Vasya And The Mushrooms

Posted lishengkangshidatiancai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C. Vasya And The Mushrooms相关的知识,希望对你有一定的参考价值。

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn = int(1e6)+100;
const int mod=998244353;
ll a[maxn],b[maxn];
ll sum[maxn],suma[maxn],sumb[maxn],sumc[maxn];
int n;
void init(){
    for(int i=n;i>=1;i--) sum[i]=sum[i+1]+a[i]+b[i];
    for(int i=n,j=n;i>=1;i--,j++) suma[i]=suma[i+1]+(i-1)*a[i]+j*b[i];
    for(int i=n,j=n+1;i>=2;i--,j++) sumb[i]=sumb[i+1]+i*b[i]+j*a[i]; 
    sumb[1]=sumb[2]+b[1];
    ll tol=0,ret=0;
    for(int i=1;i<=n;i++){
        if(i%2==1){
            ret+=tol*a[i]; tol++;
            ret+=tol*b[i]; tol++;
            sumc[i]=ret;
        }
        else{
            ret+=tol*b[i]; tol++;
            ret+=tol*a[i]; tol++;
            sumc[i]=ret;
        }
    }
}
int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
        init();
        //debug();
        ll ans=0;
        for(int i=0;i<=n;i++){
            if(i%2==0){
                ans=max(ans,sumc[i]+suma[i+1]+i*sum[i+1]);
            }
            else{
                ans=max(ans,sumc[i]+sumb[i+1]+(i-1)*sum[i+1]);
            }
        }
        printf("%lld
",ans);
}

 

以上是关于C. Vasya And The Mushrooms的主要内容,如果未能解决你的问题,请参考以下文章

C. Vasya and Multisets

cf#512 C. Vasya and Golden Ticket

Codeforces1187 C. Vasya And Array(思维,构造)

Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 二分 + 尺取

Codeforces Round #354 (Div. 2) C. Vasya and String

Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Tick