-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
59 lines (58 loc) · 1.36 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
long long t,a,b,n,i,tot,p,x,y;
static long long ar[100005],br[100005];
cin>>t;
while(t--)
{
p=0;
tot=0;
cin>>a>>b>>n;
for(i=0;i<n;i++)
cin>>ar[i];
for(i=0;i<n;i++)
{
cin>>br[i];
tot+=br[i];
}
vector< pair <long long,long long> > vect;
for (i=0; i<n; i++)
vect.push_back( make_pair(ar[i],br[i]) );
sort(vect.begin(), vect.end());
for(i=0;i<n;i++)
{
if(b%vect[i].first==0)
x=b/vect[i].first;
else
x=b/vect[i].first+1;
if(vect[i].second%a==0)
y=vect[i].second/a;
else
y=vect[i].second/a+1;
b=b-(min(x,y)*vect[i].first);
vect[i].second=vect[i].second-(min(x,y)*a);
if(i!=n-1)
{
if(b<=0)
{
p=1;
break;
}
}
else if(b<=0 && vect[i].second>0)
{
p=1;
break;
}
}
if(p==1)
cout<<"NO\n";
else
cout<<"YES\n";
}
return 0;
}