wweiyi @ 2021-02-16 10:39:46
我看了数组没有越界,然后数据也没有超,那么RE是为什么,有一个WA肯定是算法的问题,但是RE的确不知道是为什么
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
long long n,k,a[100005];
long long f[100005],g[100005];
void find(long long l,long long r)
{
long long maxn=-99999,minn=99999;
for(long long i=l;i<=r;i++)
{
maxn=max(maxn,a[i]);
minn=min(minn,a[i]);
}
f[r]=maxn;
g[r]=minn;
}
int main()
{
cin>>n>>k;
for(long long i=1;i<=n;i++)
cin>>a[i];
find(1,k);
for(long long i=k+1;i<=n;i++)
{
if(a[i]>f[i-1]&&a[i-k-1]!=f[i-1])
f[i]=a[i];
else
{
find(i-k+1,i);
continue;
}
if(a[i]<g[i-1]&&a[i-k-1]!=g[i-1])
g[i]=a[i];
else
find(i-k+1,i);
}
for(long long i=k;i<=n;i++)
cout<<g[i]<<" ";
cout<<endl;
for(long long i=k;i<=n;i++)
cout<<f[i]<<" ";
cout<<endl;
return 0;
}
by Z_301 @ 2021-02-16 10:45:13
n是
by wweiyi @ 2021-02-16 10:46:57
哦?谢谢