Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- signed main()
- {
- int n , k , g , h;
- set<int> s;
- map<int , vector<int> > v;
- cin >> n;
- for(int i = 0; i < n; i++){
- cin >> k;
- s.insert(k);
- v[k].push_back(i);
- }
- auto it = s.end();
- int x = -1 , y = -1;
- int ans = 0;
- while(it != s.begin()){
- it--;
- k = *it;
- if(x == -1){
- x = v[k][0];
- y = v[k][0];
- }
- for(int i : v[k]){
- x = min(x , i);
- y = max(y , i);
- g = abs(x - i) * k;
- h = abs(y - i) * k;
- ans = max({ans , g , h});
- }
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement