report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Brewing potion 4 - MarisaOJ: Marisa Online Judge

Brewing potion 4

Time limit: 1000 ms
Memory limit: 256 MB
Today Marisa wants to make a potion bottle out of $m$ type of mushrooms. There are $n$ mushrooms placed in a row. The $i^{th}$ mushroom is of the type $A_i$. But there are some restrictions: Marisa can't put more than $B_i$ mushrooms of type $i$ in the same bottle, because that would make the potion unstable and explode. She will choose a consecutive segment of mushrooms. Help her find the maximum number of mushrooms she can put in her potion. ### Input - The first line contains 2 integers $n, m$. - The second line contains $n$ integers $A_i$. - The third line contains $m$ integers $B$. ### Output - The maximum number of mushrooms Marisa can use. ### Constraints - $1 \le n, m \le 10^5$. - $1 \le A_i \le m$. - $0 \le B_i \le 10^5$. ### Example Input: ``` 5 3 1 2 3 2 1 1 2 1 ``` Output: ``` 4 ```
Introduction to two pointers
Merge array
Brewing potion 2
Unique elements
Small range
Number of pairs
Sum of three values
Brewing potion 3
Brewing potion 4
Three sequences
Biggest submatrix
Choosing numbers
Topic
Two pointers
Rating 900
Solution (1) Solution