LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/6/26 daily

CF 846C

signed main(){
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;++i){
        cin>>a[i];
        a[i]+=a[i-1];
    }
    vector<int>maxx(n+1);
    int l=1,r=0;
    for(int i=1;i<=n;++i){
        while(l<=r&&a[i]>a[maxx[r]])--r;
        maxx[++r]=i;
    }
    int ans1,ans2,ans3,ans=0;
    int si=0,sj,sk=0;
    for(int j=0;j<=n;++j){
        if(maxx[l]<j){
            ++l;
        }
        sk=maxx[l];
        if(a[si]<a[j]){
            si=j;
        }
        if(a[si]+a[sk]-a[j]>=ans){
            ans=a[si]+a[sk]-a[j];
            ans1=si,ans2=j,ans3=sk;
        }
    }
    cout<<ans1<<' '<<ans2<<' '<<ans3<<'\n';
}

CF 933A

int main(){
    int n;
    cin>>n;
    vector<int>dp(5);
    for(int i=1;i<=n;++i){
        int x;
        cin>>x;
        dp[1]+=(x==1);
        dp[2]=max(dp[1],dp[2]+(x==2));
        dp[3]=max(dp[2],dp[3]+(x==1));
        dp[4]=max(dp[3],dp[4]+(x==2));
    }
    cout<<dp[4]<<'\n';
}