ds題目
#include<iostream>
using namespace std;
typedef struct Node {
int index;
int data;
}node;
const int N = 10010;
node a[N];
int output[N];
int hh = 1, tt = 0;
int cnt;
bool is_max(Node r[], Node s, int hh, int tt) {
for (int i = hh; i <= tt; i++) {
if (r[i].data > s.data) return false;
}
return true;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a[i].index = i;
a[i].data = x;
}
hh = 1, tt = n;
while (hh <= tt)
{
if (is_max(a, a[hh], hh, tt))
{
cnt++;
output[a[hh].index] = cnt;
hh++;
}
else
{
a[++tt] = a[hh++];
}
}
cout << output[m] << endl;
}