#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
vector<pll> v;
vector<pll> st;
int n;
ll total = 0;
ll sum = 0;
inline bool check(pll a,pll b){
ll ta = a.fs*(sum-b.sc)+b.fs*sum;
ll tb = a.fs*sum;
if(ta>tb)return true;
else return false;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i = 0;i<n;i++){
int k;
cin>>k;
if(v.empty()||v.back().fs < k)v.push_back({k,1});
else v.back().sc++;
}
reverse(v.begin(),v.end());
for(auto &i:v){
sum += i.sc;
while(!st.empty()&&check(st.back(),i)){
total -= st.back().fs*(sum-i.sc);
i.sc += st.back().sc;
i.fs = st.back().fs;
st.pop_back();
}
total += sum*i.fs;
st.push_back(i);
}
for(auto &i:st)cout<<i.fs<<' '<<i.sc<<endl;
cout<<total;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
72 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |