#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> ii;
const int N = 1e6;
int n;
ll t[N+2], h[N+2];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
stack<ll> st;
ll ans = 0, maxi = 0, ls = 0;
for (int i = 1; i <= n; i++) {
if (t[i] > maxi) {
// cout << i << " -> " << (t[i]-t[ls])*(n-ls+1) << ' ' << t[i]*(n-i+1) << '\n';
if (ls && (t[i]-t[ls])*(n-ls+1) < t[i]*(n-i+1)) {
ans += (t[i]-t[ls])*(n-ls+1);
t[ls] = t[i];
}
else {
ans += t[i]*(n-i+1);
ls = i;
}
maxi = t[i];
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
18028 KB |
Output is correct |
2 |
Correct |
122 ms |
17880 KB |
Output is correct |
3 |
Correct |
118 ms |
18028 KB |
Output is correct |
4 |
Correct |
126 ms |
18028 KB |
Output is correct |
5 |
Correct |
119 ms |
17912 KB |
Output is correct |
6 |
Correct |
114 ms |
17900 KB |
Output is correct |
7 |
Correct |
118 ms |
17900 KB |
Output is correct |
8 |
Correct |
117 ms |
17900 KB |
Output is correct |
9 |
Correct |
116 ms |
17920 KB |
Output is correct |
10 |
Correct |
116 ms |
17900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |