1 solutions

  • 0
    @ 2022-1-10 17:23:39
    #include <iostream>
    using namespace std;
    const int N = 1e6 + 7;
    int a[N], s[N], l[N];
    int main() {
    	int n;
    	while (cin >> n && n) {
    		int opt = 0;
    		long long maxx = 0;
    		for (int i = 1; i <= n; i++) {
    			cin >> a[i];
    		}
    		a[n+1]=0;
    		for (int i = 1; i <= n + 1; i++) {
    			if (a[i] > s[opt]) s[++opt] = a[i], l[opt] = 1;
    			else {
    				int len = 0;
    				long long sum = 0;
    				while (s[opt] > a[i]) {
    					len += l[opt];
    					maxx = max(maxx, (long long)len * s[opt]);
    					opt--;
    				}
    				s[++opt] = a[i], l[opt] = len+1;
    			}
    		}
    		printf("%lld\n", maxx);
    	}
    	return 0;
    }
    

    过几天说题解

    • 1

    Information

    ID
    298
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    8
    Tags
    # Submissions
    45
    Accepted
    8
    Uploaded By