Advertisement
LEGEND2004

Container With Most Water

Oct 19th, 2023
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. signed main()
  7. {
  8.     int n , k , g , h;
  9.     set<int> s;
  10.     map<int , vector<int> > v;
  11.     cin >> n;
  12.     for(int i = 0; i < n; i++){
  13.         cin >> k;
  14.         s.insert(k);
  15.         v[k].push_back(i);
  16.     }
  17.    
  18.     auto it = s.end();
  19.     int x = -1 , y = -1;
  20.     int ans = 0;
  21.     while(it != s.begin()){
  22.         it--;
  23.         k = *it;
  24.         if(x == -1){
  25.             x = v[k][0];
  26.             y = v[k][0];
  27.         }
  28.         for(int i : v[k]){
  29.             x = min(x , i);
  30.             y = max(y , i);
  31.             g = abs(x - i) * k;
  32.             h = abs(y - i) * k;
  33.             ans = max({ans , g , h});
  34.         }
  35.        
  36.     }
  37.     cout << ans << endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement