You are given n points on the x axis, at increasing positive integer coordinates…
- User
You are given n points on the x axis, at increasing positive integer coordinates x1<x2<…<xn .
For each pair (i,j) with 1≤i<j≤n , you draw the segment [xi,xj] . The segments are closed, i.e., a segment [a,b] contains the points a,a+1,…,b .
You are given q queries. In the i -th query, you are given a positive integer ki , and you have to determine how many points with integer coordinates are contained in exactly ki segments.
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104 ). The description of the test cases follows.
The first line of each test case contains two integers n , q (2≤n≤105 , 1≤q≤105 ) — the number of points and the number of queries.
The second line of each test case contains n integers x1,x2,…,xn (1≤x1<x2<…<xn≤109 ) — the coordinates of the n points.
The third line of each test case contains q integers k1,k2,…,kq (1≤ki≤1018 ) — the parameters of the q queries.
It is guaranteed that the sum of n over all test cases does not exceed 105 , and the sum of q over all test cases does not exceed 105 .
Output For each test case, output a single line with q integers: the i -th integer is the answer to the i -th query.
c++ also verify correctness
- Assistant
- User
we have 1.5 sec per test and 10^8 ops per sec will it work?
- Assistant
To determine if the approach will work within the constraints, let's analyze the computational complexity and the input constraints:
- User
do something else sweep line or sliding window or difference array or somethign else do in nlogn or bette
- Assistant
- User
is it correct?
- Assistant
- User
You have some cards. An integer between 1 and n is written on each card: specifically, for each i from 1 to n , you have ai cards which have the number i written on them.
There is also a shop which contains unlimited cards of each type. You have k coins, so you can buy at most k new cards in total, and the cards you buy can contain any integer between 1 and n , inclusive.
After buying the new cards, you must partition all your cards into decks, according to the following rules:
all the decks must have the same size; there are no pairs of cards with the same value in the same deck. Find the maximum possible size of a deck after buying cards and partitioning them optimally.
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104 ). The description of the test cases follows.
The first line of each test case contains two integers n , k (1≤n≤2⋅105 , 0≤k≤1016 ) — the number of distinct types of cards and the number of coins.
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤1010 , ∑ai≥1 ) — the number of cards of type i you have at the beginning, for each 1≤i≤n .
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
Output For each test case, output a single integer: the maximum possible size of a deck if you operate optimally.
- Assistant