Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
142388 | baim. | 音乐会 | C++ | 解答错误 | 0 | 102 MS | 6116 KB | 719 | 2024-04-07 19:08:56 |
#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; }