TOPIC

10% alguma dica ?

Ygor Ribeiro asked 2 years ago

#include<bits/stdc++.h>

using namespace std;

long long vet[100005], ans, maior;

vector<vector<long long> > v;

int main(){
    int n;
    while(scanf("%d",&n),n){
        v.assign(n+1, vector<long long> ());
        for(int i=0;i<n;i++) scanf("%lld",vet+i);

        int indice = 0;
        maior = ans = 0;

        for(int i=0;i<n;i++){
            if(vet[i] >= maior){
                maior = vet[i];
                v[indice].push_back(vet[i]);
            }else{
                indice++;
                v[indice].push_back(vet[i]);
                maior = vet[i];
            }
        }

        for(int i=0;i<=indice;i++){
            int q = 0;
            for(int j=0;j<v[i].size();j++){
                q = 0;
                if(i-1 >= 0 && j == 0){
                    int t = v[i-1].size() - 1;
                    while(v[i-1][t] > v[i][j]){
                        q++;
                        t--;
                    }
                }
                //printf("q = %d tam = %d valor %lld\n",q,v[i].size()-j, v[i][j]);
                ans = max(ans, (v[i].size() - j + q) * v[i][j]);
            }
        }

        printf("%lld\n",ans);

    }

    return 0;
}

Remember not post solutions. Your post may be reviewed by our moderators.

  • Diego Rangel replied 2 years ago

    Eu pesquisaria sobre o algoritmo do histograma.