|
| 1 | +#include<bits/stdc++.h> |
| 2 | + |
| 3 | +using namespace std; |
| 4 | + |
| 5 | +#define ms(x,v) memset(x,(v), sizeof(x)) |
| 6 | +#define msn(x,v,n) memset(x,(v),sizeof(x[0]) * n) |
| 7 | +#define INF 0x3f3f3f3f |
| 8 | +#define random(a,b) (rand() % ((b) -(a)) +(a)) |
| 9 | + |
| 10 | +typedef long long LL; |
| 11 | +typedef pair<int,int> PII; |
| 12 | + |
| 13 | +const double EPS = 2e-8; |
| 14 | + |
| 15 | + |
| 16 | +bool cmp(const PII & a,const PII & b){ |
| 17 | + //a.first /a.second > b.first /b.second |
| 18 | + return a.first * b.second > a.second * b.first; |
| 19 | +} |
| 20 | + |
| 21 | +bool check(double c,double e,double a,double b){ |
| 22 | + if(c + EPS <a || e +EPS < b )return false; |
| 23 | + double f = a /(c+EPS); |
| 24 | + if(c < EPS) return e+EPS >=b; |
| 25 | + return (1 - f) * e +EPS>=b ; |
| 26 | +} |
| 27 | + |
| 28 | +struct Query{ |
| 29 | + int a,b; |
| 30 | + int id; |
| 31 | + bool ans; |
| 32 | +}; |
| 33 | + |
| 34 | +void solve(){ |
| 35 | + |
| 36 | + int D,S; |
| 37 | + cin >> D >> S; |
| 38 | + vector<PII> dd(S); |
| 39 | + for(int i=0 ; i<S ; ++i)cin >> dd[i].first >> dd[i].second; |
| 40 | + |
| 41 | + sort(dd.begin(), dd.end(), cmp); |
| 42 | + |
| 43 | + vector<int> sumC(S+1,0),sumE(S+1,0); |
| 44 | + |
| 45 | + for(int i=1; i<=S; ++i) |
| 46 | + sumC[i] = sumC[i-1] + dd[i-1].first; |
| 47 | + for(int i=S-1 ; i >=0 ; --i) |
| 48 | + sumE[i] = sumE[i+1] + dd[i].second; |
| 49 | + vector<Query> qq(D); |
| 50 | + for(int i=0 ; i< D ; ++i)cin >> qq[i].a >> qq[i].b, qq[i].id = i; |
| 51 | + |
| 52 | + sort(qq.begin(),qq.end(),[](const Query& x,const Query &y)->bool{return x.a < y.a;}); |
| 53 | + |
| 54 | + int pointer = 0; |
| 55 | + for(int i=0 ; i< S && pointer<D ; pointer++){ |
| 56 | + auto & cur = qq[pointer]; |
| 57 | + while (i<S-1 && sumC[i+1] < cur.a) |
| 58 | + ++i; |
| 59 | + if(sumC[i+1]>=cur.a && sumE[i+1]>=cur.b){ |
| 60 | + cur.ans = true; |
| 61 | + }else{ |
| 62 | + cur.ans = check(dd[i].first,dd[i].second,cur.a - sumC[i],cur.b - sumE[i+1]); |
| 63 | + } |
| 64 | + } |
| 65 | + sort(qq.begin(),qq.end(),[](const Query&x,const Query&y)->bool{return x.id < y.id;}); |
| 66 | + |
| 67 | + cout << " "; |
| 68 | + for(const auto & e : qq) |
| 69 | + cout << (e.ans?'Y':'N'); |
| 70 | +} |
| 71 | + |
| 72 | +int main(int argc, char const *argv[]) |
| 73 | +{ |
| 74 | + |
| 75 | + ios :: sync_with_stdio(0); |
| 76 | + cin.tie(0); |
| 77 | + // cout.tie(0); |
| 78 | + std::cout.precision(8); |
| 79 | + std::cout.setf( std::ios::fixed, std:: ios::floatfield ); |
| 80 | + int T; |
| 81 | + cin >> T; |
| 82 | + |
| 83 | + for(int kase =1; kase <= T ; ++kase) |
| 84 | + { |
| 85 | + cout << "Case #"<<kase << ":"; |
| 86 | + |
| 87 | + solve(); |
| 88 | + cout << '\n'; |
| 89 | + } |
| 90 | + |
| 91 | + return 0; |
| 92 | +} |
0 commit comments