120题 答案

zhengchenhao1 2022-06-17 20:10:00 0

#include <bits/stdc++.h>

using namespace std;

int main() {

freopen("B.in", "r", stdin);

freopen("B.out", "w", stdout);

int n, num[10000], index = 0, maxSize = 0;

stack stk;

cin >> n;

for (int i = 0; i < n; i++) cin >> num[i];

for (int i = 0; i < n; i++) {

stk.push(i + 1);

maxSize = max(maxSize, (int)stk.size());

while (!stk.empty() && stk.top() == num[index]) {

    stk.pop();

    index++;

}

}

if (stk.empty()) {

cout << "yes\n" << maxSize;

} else {

cout << "no";

}

return 0; }

{{ vote && vote.total.up }}