C. Place for a Selfie

C. Place for a Selfie

The universe is a coordinate plane. There are n space highways, each of which is a straight line y=kx passing through the origin (0,0). Also, there are m asteroid belts on the plane, which we represent as open upwards parabolas, i. e. graphs of functions y=ax2+bx+c, where a>0.

You want to photograph each parabola. To do this, for each parabola you need to choose a line that does not intersect this parabola and does not touch it. You can select the same line for different parabolas. Please find such a line for each parabola, or determine that there is no such line.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t104). The description of the test cases follows.

The first line of each test case contains 2 integers n and m (1n,m105) —the number of lines and parabolas, respectively.

Each of the next n lines contains one integer k (|k|108), denoting a line that is described with the equation y=kx. The lines are not necessarily distinct, k can be equal to 0.

Each of the next m lines contains 3 integers a, b, and c (a,|b|,|c|108, a>0) — coefficients of equations of the parabolas ax2+bx+c. The parabolas are not necessarily distinct.

It is guaranteed that the sum n over all test cases does not exceed 105, and the sum m over all test cases also does not exceed 105.

Output

For each test case, output the answers for each parabola in the given order. If there is a line that does not intersect the given parabola and doesn't touch it, print on a separate line the word "YES", and then on a separate line the number k — the coefficient of this line. If there are several answers, print any of them. If the line does not exist, print one word "NO".

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

The empty lines in the output in the example are given only for illustration, you do not need to output them (but you can).

Example

input

复制代码
5
1 2
1
1 -1 2
1 -1 3
2 2
1
4
1 2 1
2 5 1
1 1
0
1 0 0
1 1
100000000
100000000 100000000 100000000
2 3
0
2
2 2 1
1 -2 1
1 -2 -1
复制代码

output

复制代码
YES
1
YES
1

YES
1
YES
4

NO

YES
100000000

YES
0
NO
NO
复制代码

Note

In the first test case, both parabolas do not intersect the only given line y=1x, so the answer is two numbers 1.

In the second test case, the line y=x and the parabola 2x2+5x+1 intersect, and also the line y=4x and the parabola x2+2x+1 touch, so these pairs do not satisfy the condition. So for the first parabola, the answer is 1 (y=1x), and for the second parabola — 4.

In the third test set, the line and the parabola intersect, so the answer is "NO".

 

解题思路

  求一个k使得直线y=kx与抛物线ax2+bx+c不能有交点。其中如果直线与抛物线有交点,那么就会有等式ax2+bx+c=kx,即ax2+(bk)x+c=0。现在不能有交点意味着Δ=(bk)24ac<0。因此问题就变成了能否在给定的斜率中找到满足Δ<0k

  容易知道(bk)24ac也是一个抛物线,当k=b时能够取到最小值。因此我们可以先对给定的斜率进行排序,然后二分出来b的最小的k,以及b的最大的k。只要有然后把k代入到这个不等式中,只要有一个使得Δ<0,那么我们就找到一个k使得直线与抛物线没有交点。否则无解。

  AC代码如下:

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 typedef long long LL;
 5 
 6 const int N = 1e5 + 10;
 7 
 8 int k[N];
 9 
10 void solve() {
11     int n, m;
12     scanf("%d %d", &n, &m);
13     for (int i = 0; i < n; i++) {
14         scanf("%d", k + i);
15     }
16     sort(k, k + n);
17     while (m--) {
18         LL a, b, c;
19         scanf("%lld %lld %lld", &a, &b, &c);
20         int l = 0, r = n - 1;
21         while (l < r) {
22             int mid = l + r >> 1;
23             if (k[mid] >= b) r = mid;
24             else l = mid + 1;
25         }
26         if ((b - k[l]) * (b - k[l]) < 4 * a * c) {
27             printf("YES\n%d\n", k[l]);
28         }
29         else {
30             l--;
31             if (l >= 0 && (b - k[l]) * (b - k[l]) < 4 * a * c) printf("YES\n%d\n", k[l]);
32             else printf("NO\n");
33         }
34     }
35 }
36 
37 int main() {
38     int t;
39     scanf("%d", &t);
40     while (t--) {
41         solve();
42     }
43     
44     return 0;
45 }
复制代码

 

参考资料

  Editorial of Codeforces Round #862 (Div. 2):https://codeforces.com/blog/entry/114644

posted @   onlyblues  阅读(113)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
历史上的今天:
2022-04-04 牛奶工厂
Web Analytics
点击右上角即可分享
微信分享提示