This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
signed main() {
int n,_q; cin>>n>>_q;
vector<int>v(n);
for(auto &z : v)
cin>>z;
while(_q--) {
int l,r; cin>>l>>r;
l--,r--;
vector<int>nw;
for(int ll = l ; ll <= r ; ll++) {
nw.push_back(v[ll]);
}
sort(nw.rbegin(),nw.rend());
int len = r-l+1;
int ans=0;
for(int i = len-1 ; i >= 0 ; i--) {
int curr = min(i+1,nw[i]);
ans=max(ans,curr);
}
cout << ans << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |