1 solutions

  • 1
    @ 2024-10-7 11:58:41

    #include<bits/stdc++.h> using namespace std; const int maxn=1e5+5; int n,d[maxn],ans; void solve(int lo,int hi){ int minv=10005,pos=-1; if(hi-lo<=1){ ans+=max(d[lo],d[hi]); return; } for(int i=lo;i<=hi;i++){ if(minv>d[i]){ minv=d[i]; pos=i; } } ans+=minv; for(int i=lo;i<=hi;i++){ d[i]-=minv; } solve(lo,pos-1); solve(pos+1,hi); } int main() { cin>>n; for(int i=1;i<=n;i++){ cin>>d[i]; } solve(1,n); cout<<ans; return 0; }

    • 1

    Information

    ID
    2184
    Time
    1000ms
    Memory
    125MiB
    Difficulty
    9
    Tags
    # Submissions
    10
    Accepted
    9
    Uploaded By