Pagini recente » Cod sursa (job #2054045) | Cod sursa (job #534226) | Cod sursa (job #2775210) | Cod sursa (job #522975) | Cod sursa (job #305909)
Cod sursa(job #305909)
var m,n,p,q,i,v,j,c:longint;
a,b:array[1..2500]of integer;
f,g:text;
begin
assign(f,'stramosi.in');
reset(f);
assign(g,'stramosi.out');
rewrite(g);
read(f,n,m);
for i:=1 to n do begin
read(f,a[i]);
b[i]:=a[i];
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
v:=a[i];
a[i]:=a[j];
a[j]:=v;
end;
for i:=1 to m do
begin
read(f,q,p);
j:=0;
while a[i]<>b[q] do inc(c);
while (j<p)and(c>1) do
begin
dec(c);
if (a[c]<a[c+1])and(j>1) then inc(j);
v:=a[c];
end;
if j=p then
begin
j:=1;
while b[j]<>a[c] do inc(j);
writeln(g,j);
end
else writeln(g,'0');
end;
close(f);
close(g);
end.