堆宝塔
作者:
晴斋
,
2024-03-07 17:12:23
,
所有人可见
,
阅读 27
#include <iostream>
using namespace std;
const int N = 1010;
int a[N], b[N], sa, sb;
int n;
int main()
{
cin >> n;
int cnt = 0, res = 0;
for (int i = 1; i <= n; i ++)
{
int c;
cin >> c;
if (sa == 0 || c < a[sa-1])
{
a[sa++] = c;
}
else if (sb == 0 || c > b[sb-1])
{
b[sb++] = c;
}
else
{
res ++;
cnt = max(cnt, sa);
sa = 0;
while(c < b[sb-1])
{
a[sa++] = b[sb-1];
sb--;
}
a[sa++] = c;
}
}
if (sa)
{
res ++;
cnt = max(cnt, sa);
}
if (sb)
{
res ++;
cnt = max(cnt, sb);
}
cout << res << ' ' << cnt << endl;
return 0;
}