Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long int
- using namespace std;
- int main() {
- int t ;
- cin>>t ;
- while(t--){
- ll m,n,k ;
- cin>>m>>n>>k ;
- vector<ll>arr(m),brr(m) ;
- for(ll i=0;i<m;i++){
- cin>>arr[i] ;
- }
- for(ll j=0;j<m;j++){
- cin>>brr[j] ;
- }
- ll ans=0 ;
- ll st=0 , en=1e9 ;
- while(st<=en){
- ll mid=st+((en-st)/2) ;
- vector<ll> temp(m) ;
- for(int i=0;i<m;i++){
- ll a=((mid-arr[i])/brr[i])+1 ;
- if(mid<arr[i])temp[i]=0 ;
- else
- temp[i]=a ;
- }
- ll sum=0 ;
- sort(temp.begin(),temp.end(),greater<int>()) ;
- for(ll i=0;i<min(n,m);i++){
- sum+=temp[i] ;
- }
- if(sum>=k){ans=mid ; en=mid-1 ;}
- else st=mid+1 ;
- }
- cout<<ans<<endl ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement