#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define int long long
#define fi first
#define se second
const int N = 3e5 + 5, M = 1e9 + 7, LG = 20;
int n , A[N] ,q , l ,r;
void solve(){
cin >> n >> q;
for (int i=1 ; i<=n ; i++) cin >> A[i];
while(q--){
cin >> l >> r;
vector<int> s;
for (int k=l ; k<=r ; k++){
s.pb(A[k]);
}
sort(s.begin() , s.end());
reverse(s.begin() , s.end());
int ans = 0;
for (int i=0 ; i<s.size() ; i++){
if (s[i] >= i+1){
ans = i+1;
}
}
cout << ans << endl;
}
}
signed main(){
// freopen("" , "r" , stdin);
// freopen("" , "w" , stdout);
// cout << setprecision(30);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ts = 1;
// cin >> ts;
while(ts--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |