fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie()
  4.  
  5.  
  6.  
  7. using namespace std;
  8. typedef long long ll;
  9.  
  10.  
  11. void File(){
  12. #ifndef ONLINE_JUDGE
  13. freopen("input.txt", "r", stdin);
  14. freopen("output.txt", "w", stdout);
  15. #endif
  16. }
  17.  
  18. int solve() {
  19. int n;
  20. cin>>n;
  21. vector<int> v(n),temp;
  22. set<int> set;
  23.  
  24. for(int i=0;i<n;i++){
  25. cin>>v[i];
  26. set.insert(v[i]);
  27. }
  28. stack<int> stack;
  29.  
  30. for(auto i:set){
  31. stack.push(i);
  32. }
  33.  
  34. ll mx=0,counter=0,mxArea=0;
  35.  
  36. while(!stack.empty()){
  37. for(int i=0;i<n;i++){
  38. if(v[i]>=stack.top()){
  39. temp.push_back(1);
  40. }else{
  41. temp.push_back(0);
  42. }
  43. }
  44.  
  45. for(int i=0;i<n;i++){
  46. if(temp[i]==1){
  47. counter++;
  48. }else if(counter!=0 && mx<counter){
  49. mx=counter;
  50. counter=0;
  51. }else{
  52. counter=0;
  53. }
  54. }
  55. if(counter!=0 && mx<counter){
  56. mx=counter;
  57. }
  58.  
  59. mxArea=max(mxArea,(stack.top()*mx));
  60.  
  61. stack.pop();
  62. temp.clear();
  63. mx=0;
  64. counter=0;
  65. }
  66. cout<<mxArea<<endl;
  67. return 0;
  68. }
  69.  
  70. int main() {
  71. fastio();
  72. File();
  73. int32_t t=1;
  74. cin>>t;
  75. for(auto i=t;i--;){
  76. solve();
  77. }
  78. }
  79.  
  80.  
Success #stdin #stdout 0.01s 5288KB
stdin
2
7
2 1 4 5 1 3 3
4
1000 1000 1000 1000
stdout
8
4000