听灌多,求助(P1318,马蜂良好)
  • 板块灌水区
  • 楼主Berd__
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/9/25 18:45
  • 上次更新2024/9/25 20:56:41
查看原帖
听灌多,求助(P1318,马蜂良好)
959419
Berd__楼主2024/9/25 18:45
#include<bits/stdc++.h>
using namespace std;
int n,ans,maxx=-0x3f3f3f3f;
int b[10005];
int main(){
	cin>>n;
    int tmp;
    for(int i=0;i<n;i++){
        cin>>tmp;
        ans-=tmp;
        maxx=max(tmp,maxx)==tmp?i:maxx;
        b[i]=tmp;
    }
    tmp=-0x3f3f3f3f;
    for(int i=0;i<n,i!=maxx;i++){
        tmp=max(tmp,b[i]);
        ans+=tmp;
        //cout<<tmp<<" "<<ans<<endl;
    }
    tmp=-0x3f3f3f3f;
    for(int i=n-1;i>0,i+1!=maxx;i--){
        tmp=max(tmp,b[i]);
        ans+=tmp;
        //cout<<tmp<<" "<<ans<<endl;
    }
	cout<<ans;
} 

2024/9/25 18:45
加载中...