# 单调队列 滑动窗口 python代码

## 题意

The array is [1,3,-1,-3,5,3,6,7][1,3,−1,−3,5,3,6,7], and k = 3k=3。

8 3
1 3 -1 -3 5 3 6 7

-1 -3 -3 -3 3 3
3 3 5 5 6 7


n, k = map(int,input().split())
du = map(int, input().split())#注意这种读入方式
du = list(du)

tail = -1
dui = list(range(1000001))
op = list(range(1000001))
p = list(range(1000001))
for i in range(0,n):
op[i+1] = du[i]

tail = 0
for i in range(1, n+1):
while dui[tail] >= op[i] and tail >= head :
tail = tail -1
tail = tail + 1
dui[tail] = op[i]
p[tail] = i
while p[head] <= i - k :

if i>=k:
if i == n :
else:

tail = 0
for i in range(0,n):
op[i+1] = du[i]

for i in range(1, n+1):

while dui[tail] <= op[i] and tail >= head :
tail = tail -1
tail = tail + 1
dui[tail] = op[i]
p[tail] = i
while p[head] <= i - k:

if i>=k:



## 解：

03-25 45

08-06 105

12-20 332

05-09 338

05-30 2102

07-28 44

03-06 669

03-29 86

01-15 558

08-08 1095

04-03 52

03-20 61

07-30 97

09-05 553

04-25 570

05-11 49

07-18 91

03-28 509

04-21 91

03-19 81万+

04-14 58万+

03-13 14万+

03-01 13万+

03-04 13万+

03-05 5653

03-05 5万+

03-08 4万+

03-08 7万+

03-10 12万+

03-10 18万+

03-12 11万+

03-13 11万+

03-16 10万+

03-18 8598

03-19 8万+

03-20 7370

03-22 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-26 1万+

03-27 4万+

03-29 21万+

03-29 10万+

03-30 16万+

05-28 5083

04-01 6794

04-02 1万+

04-02 4万+

04-06 7万+

04-07 5万+

04-09 8万+

04-09 2万+

05-17 7333

04-11 3万+

04-15 5万+

04-18 4万+

04-20 4万+

04-24 3万+

04-29 5778

04-30 8240

05-16 5万+

05-06 1万+

05-08 4万+

05-11 3万+

05-12 2348

05-12 1万+

05-14 5579

05-16 3101

05-16 1万+

05-18 7577

05-24 3958

05-18 2902

05-19 9699

05-24 2704

05-25 1330

#### JAVA入门基础知识常用DOS指令、注释、常量、数据类型、运算符等

©️2019 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客