forked from mrsac7/CSES-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1142 - Advertisement.cpp
More file actions
41 lines (37 loc) · 970 Bytes
/
1142 - Advertisement.cpp
File metadata and controls
41 lines (37 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Advertisement
//
// Problem name: Advertisement
// Problem Link: https://cses.fi/problemset/task/1142
// Author: Bernardo Archegas (https://codeforces.com/profile/Ber)
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXN 200100
#define INF 100000000
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int M = 998244353;
int v[MAXN];
int main () { _
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i];
v[n+1] = 0;
vector<pii> sk;
sk.pb({v[1], 1});
ll ans = 0;
for (int i = 2; i <= n+1; i++) {
while (!sk.empty() && sk.back().F >= v[i]) {
ans = max(ans, 1ll * (i-1 - ((int)sk.size() == 1 ? 0 : sk[(int)sk.size()-2].S)) * sk.back().F);
sk.pop_back();
}
sk.pb({v[i], i});
}
cout << ans << '\n';
return 0;
}