#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
for (int qwerty = 0; qwerty < q; qwerty++) {
int l, r;
cin >> l >> r;
priority_queue<int> pq;
for (int i = l; i <= r; i++) pq.push(arr[i-1]);
int ans = 0;
while (true) {
if (pq.empty()) break;
if (pq.top() < ans) break;
ans++;
pq.pop();
}
cout << ans << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |