#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
const int MAXN = 5013;
int N;
int arr[MAXN];
vi compress;
int lpref[MAXN], rpref[MAXN];
ll ans;
int indexof(int x)
{
return LB(ALL(compress), x) - compress.begin();
}
int32_t main()
{
cout << fixed << setprecision(12);
cerr << fixed << setprecision(4);
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N;
FOR(i, 0, N)
{
cin >> arr[i];
compress.PB(arr[i]);
}
int idx = max_element(arr, arr + N) - arr;
sort(ALL(compress));
compress.erase(unique(ALL(compress)), compress.end());
FOR(i, 0, idx)
{
int lo = indexof(arr[i]), hi = indexof(arr[i + 1]);
if (lo > hi) swap(lo, hi);
lpref[lo]++; lpref[hi]--;
}
FOR(i, idx, N - 1)
{
int lo = indexof(arr[i]), hi = indexof(arr[i + 1]);
if (lo > hi) swap(lo, hi);
rpref[lo]++; rpref[hi]--;
}
FOR(i, 1, SZ(compress))
{
lpref[i] += lpref[i - 1];
rpref[i] += rpref[i - 1];
}
FOR(i, 0, SZ(compress) - 1)
{
int h = compress[i + 1] - compress[i];
ans += h * max(lpref[i], rpref[i]);
// cerr << h << ' ' << max(lpref[i], rpref[i]) << endl;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
5 |
Incorrect |
7 ms |
512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
5 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
8 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |