Skip to content

Instantly share code, notes, and snippets.

@qjatn0120
Created April 2, 2023 18:01
Show Gist options
  • Save qjatn0120/1a25554956009136208361ec447d42bd to your computer and use it in GitHub Desktop.
Save qjatn0120/1a25554956009136208361ec447d42bd to your computer and use it in GitHub Desktop.
#ifdef DEBUG
#include "debug.h"
#endif // DEBUG
#ifndef DEBUG
template <typename T>
void debug(T &x){}
#endif // DEBUG
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(nullptr), ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
vector <long long int> k(n);
for(int i = 0; i < n; i++) cin >> k[i];
sort(k.begin(), k.end());
for(int i = 0; i < m; i++){
long long int a, b, c;
cin >> a >> b >> c;
long long int ans;
bool flag = false;
auto it = lower_bound(k.begin(), k.end(), b);
if(it != k.end()){
long long int val = *it;
if((b - val) * (b - val) - 4 * a * c < 0) flag = true, ans = val;
}
if(it != k.begin()){
it--;
long long int val = *it;
if((b - val) * (b - val) - 4 * a * c < 0) flag = true, ans = val;
}
if(flag) cout << "YES\n" << ans << "\n";
else cout << "NO\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment