# 111qqz的小窝

## leetcode 209. Minimum Size Subarray Sum (尺取法)

Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 instead.

For example, given the array [2,3,1,2,4,3] and s = 7,
the subarray [4,3] has the minimal length under the problem constraint

## 1800: [Ahoi2009]fly 飞行棋

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1530  Solved: 1220
[Submit][Status][Discuss]

8
1
2
2
3
1
1
3
3

3

N<= 20

## codeforces 220 E. Little Elephant and Inversions (树状数组+尺取)

how many pairs of integers l and r are there, such that 1 ≤ l < rn and sequence b = a1a2alarar + 1an has no more than k inversions.

hdu 4123 题目链接

## codeforces 660 C. Hard Process (ruler)

cf660C

solution:ruler.1A

hdu 3530题目链接

## codeforces 279 B books

http://codeforces.com/problemset/problem/279/B

## codeforces #321 div 2 B. Kefa and Company(尺取法)

B. Kefa and Company
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.

Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn’t want any friend to feel poor compared to somebody else in the company (Kefa doesn’t count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!

Input

The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, ) — the number of Kefa’s friends and the minimum difference between the amount of money in order to feel poor, respectively.

Next n lines contain the descriptions of Kefa’s friends, the (i + 1)-th line contains the description of the i-th friend of type misi(0 ≤ mi, si ≤ 109) — the amount of money and the friendship factor, respectively.

Output

Print the maximum total friendship factir that can be reached.

Sample test(s)
input

output

input

output

Note

In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.

In the second sample test we can take all the friends.

## poj 3320 Jessica’s Reading Problem (尺取法)

 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8787 Accepted: 2824

Description

Jessica’s a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a very thick text book. The author of that text book, like other authors, is extremely fussy about the ideas, thus some ideas are covered more than once. Jessica think if she managed to read each idea at least once, she can pass the exam. She decides to read only one contiguous part of the book which contains all ideas covered by the entire book. And of course, the sub-book should be as thin as possible.

A very hard-working boy had manually indexed for her each page of Jessica’s text-book with what idea each page is about and thus made a big progress for his courtship. Here you come in to save your skin: given the index, help Jessica decide which contiguous part she should read. For convenience, each idea has been coded with an ID, which is a non-negative integer.

Input

The first line of input is an integer P (1 ≤ P ≤ 1000000), which is the number of pages of Jessica’s text-book. The second line contains P non-negative integers describing what idea each page is about. The first integer is what the first page is about, the second integer is what the second page is about, and so on. You may assume all integers that appear can fit well in the signed 32-bit integer type.

Output

Output one line: the number of pages of the shortest contiguous part of the book which contains all ideals covered in the book.

Sample Input

Sample Output

我们先来介绍一下尺取法。尺取法，顾名思义，像尺子一样，一块一块的截取。是不是解释的有点让人纳闷～。。没关系，下面我们通过这个题目来体会尺取法的魅力。

给定长度为n的数列整数a0,a1,a2,a3 ….. an-1以及整数S。求出综合不小于S的连续子序列的长度的最小值。如果解不存在，则输出0。

限制条件：

10

0

S<10^8

这幅图便是尺取法怎么“取”的过程了。

整个过程分为4布：

1.初始化左右端点

2.不断扩大右端点，直到满足条件

3.如果第二步中无法满足条件，则终止，否则更新结果

4.将左端点扩大1，然后回到第二步

然后这道题可以先用set ，统计出不同的知识点有多少个，总是记为total

因为知识点的标号比较大，数组下表存不下，所以开个map来统计相应知识点出现的数量…

然后还有个．．．

误以为if (cnt[a[tail++]]++==0) sum++;和

if (cnt[a[tail]]==0)

{

sum++;

cnt[a[taill]]++;

tail++;

}

是等价的．．．