Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
142100 杨博煊 音乐会 C++ 解答错误 0 99 MS 6116 KB 719 2024-04-06 16:35:17

Tests(0/10):


#include<bits/stdc++.h> using namespace std; vector<int>height; int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ int x;cin>>x; height.push_back(x); } if(height.size()==0)cout<<0; else{ stack<int> s; int ans=0; int t; for(int i=0;i<height.size();i++) { while(s.size()&&height[s.top()]<height[i]) { t=s.top(); s.pop(); if(!s.size())break; int l=s.top(); int r=i; int w=r-l-1; ans+=(min(height[i],height[l])-height[t])*w; } s.push(i); } cout<<ans; } return 0; }


测评信息: