Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program task3;
- type
- Tnode = record
- index, NData: integer;
- end;
- var
- size, maxSize: integer;
- head, tail: integer;
- Datamax,datamin: array of tnode;
- ans: tnode;
- n, i, k, d, t, prov: integer;
- m, min: array [1..1000] of integer;
- procedure newArrayQueue(maxSize: integer);
- begin
- SetLength(Datamax, maxSize);
- head := -1;
- size := 0;
- tail := -1;
- end;
- function pushData(DData, index: integer): boolean;
- begin
- if size = maxsize then
- exit(False);
- head := head mod maxSize;
- Datamax[head].ndata:= DData;
- Datamax[head].index := index;
- size += 1;
- end;
- function popDatahead(): boolean;
- begin
- if (size = 0) then
- exit(False);
- size -= 1;
- head := head mod maxsize + 1;
- end;
- function popDatatail(): boolean;
- begin
- if (size = 0) then
- exit(False);
- size -= 1;
- tail := tail mod maxsize - 1;
- end;
- function getData(): integer;
- begin
- exit(Datamax[tail].ndata);
- end;
- begin
- Assign(input, 'input.txt');
- Assign(output, 'output.txt');
- reset(input);
- rewrite(output);
- readln(n, k);
- newArrayQueue(n + 2);
- t := 2;
- for i := 1 to n do
- begin
- Read(m[i]);
- end;
- pushdata( m[i], 1);
- Write(m[1]);
- min[1] := m[1];
- for i := 2 to n do
- begin
- d := m[i];
- while (size > 0) and (head < d) do
- PopDataHead();
- // while (p1^.size > 0) and (p1^.head > d) do
- // PopDataHead(p1);
- if size = 0 then
- begin
- head := 0;
- tail := 0;
- end;
- //if p1^.size = 0 then
- // begin
- // p1^.head := 0;
- // p1^.tail := 0;
- // end;
- PushData(m[i], i);
- // PushData(p1, m[i], i);
- if Datamax[tail].index < (i - k + 1) then
- PopDataTail();
- // if p1^.Data[p^.tail].index < (i - k + 1) then
- // PopDataTail(p1);
- prov := GeTdata();
- Write(GeTdata());
- min[t] := GeTdata();
- t += 1;
- end;
- t -= 1;
- if m[n - 1] > m[n] then
- Write(m[n - 1])
- else
- Write(m[n]);
- Write(m[n]);
- { if m[n - 1] < m[n] then
- min[t + 1] := m[n - 1]
- else
- min[t + 1] := m[n];
- min[t + 2] := m[n];
- writeln;
- for i := 1 to t + 2 do
- begin
- Write(min[i]);
- end;}
- Close(input);
- Close(output);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement