#P12000. 扶苏出勤日记

    ID: 13465 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>二分单调队列洛谷原创O2优化ST 表洛谷月赛

扶苏出勤日记

Problem Description

Fusu is a maimai (舞萌) fan. In the next nn days, she will play maimai every day, and she hopes that the number of rounds she plays each day is the same.

Playing one round of maimai costs a fixed 11 game coin. However, the price of game coins may change every day. Specifically, on day ii, one yuan can buy aia_i game coins.

By doing black work for Luogu, Fusu will earn some income every day. She will earn bib_i yuan on day ii.

Each day, Fusu will first receive that day’s income bib_i, then buy game coins, and then play maimai.

Each day, Fusu may use any amount of the money she has to buy game coins at that day’s exchange rate. That is, she does not have to exchange all her money at once: she may spend only part of her money to buy game coins on that day, and save the remaining money for buying game coins in future days. Also, she does not have to spend all her game coins in one day: she may spend only part of them that day, and save the remaining game coins to play in later days.

Fusu knows the exchange rate and her income for each of the next nn days. She wants to play the same number of rounds of maimai every day during these nn days. Therefore, she wants to know: under an optimal strategy for buying game coins, what is the maximum number of rounds she can play per day?

Input Format

This problem contains multiple test cases within a single test point. The first line contains a positive integer TT, the number of test cases. For each test case:

The first line contains an integer nn, the total number of days.
The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n, where aia_i is the number of coins that 1 yuan can buy on day ii.
The third line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n, where bib_i is Fusu’s income on day ii.

Output Format

For each test case, output one line with one integer, the answer.

3
5
1 2 3 4 5
5 4 3 2 1
5
1 1 1 1 1
2 3 4 5 6
9
9 9 8 2 4 4 3 5 3
10 10 10 10 10 10 10 10 10
5
2
55

Hint

Constraints

Let NN be the sum of nn over all test cases in a single test point.

  • For 20%20\% of the data, 1n31 \leq n \leq 3, N1000N \leq 1000.
  • For 40%40\% of the data, 1n20001 \leq n \leq 2000, N10000N \leq 10000.
  • For 60%60\% of the data, 1n1051 \leq n \leq 10^5, N2×105N \leq 2 \times 10^5.
  • Another 10%10\% of the data satisfies aiai+1a_i \geq a_{i+1} for 1in11 \leq i \leq n-1.
  • Another 10%10\% of the data satisfies aiai+1a_i \leq a_{i+1} for 1in11 \leq i \leq n-1.
  • For 100%100\% of the data, 1n1061 \leq n \leq 10^6, 1ai10001 \leq a_i \leq 1000, 1bi1091 \leq b_i \leq 10^9, nN2×106n \leq N \leq 2 \times 10^6, 1T2×1061 \leq T \leq 2 \times 10^6.

Translated by ChatGPT 5