Language: C++

#include "bits/stdc++.h"
using namespace std ;


long long a[1000005];
long long f[1000005] ;
long long N , K , x ;
bool check( long long m ){
	long long c = 0 ;
	for( int i = 1 ; i <= N ; i++ ){
		c += max(0,( a[i] - m/f[N-i+1])) ;
		if(c>K) return false ;
	}
	return true ;
}

int main(){
	
	cin >> N >> K ;

	for( int i = 0 ; i < N ; i++ ){
		cin >> a[i+1] ;
	}
	for( int i = 0 ; i < N ; i++ ){
		cin >> f[i+1] ;
	}
	sort(a+1,a+N+1);
	sort(f+1,f+N+1);
	long long l = 0 , r = a[N]*f[N] , m ;
	while(l <= r){
		m = (l+r)/2 ;
		if(check(m)) r=m-1 ;
		else l = m+1 ;
	}
	if( check(l) )
		cout << l << endl ;
	else if( K == 0 ){
		long long ans = 0 ;
		for( int i = 1 ; i <= N ; i++ ){
			ans = max((a[i]*f[N-i+1]),ans);
		}
		cout << ans << endl ;
	}
	// long long cur = a[N] , c = 1 , i = N , C = 0 ;
	// while( K > 0 && i > 0  ){
	// 	// cout << K << " " << cur << " " << c << " " << i << endl ;
	// 	if( c * ( cur-a[i-1]) <= K  ){
	// 		K = K - c * ( cur-a[i-1]) ;
	// 		cur = a[i-1]; 
	// 		c++ ;
	// 		i--;
	// 		// cout << K << endl ;
	// 	}
	// 	else{
	// 		cur = cur - K/c ;
	// 		C = K % c ;
	// 		K = 0 ;
	// 	}
	// }
	// // cout << K << " " << cur << " " << c << endl ;
	// for( int i = 0 ; i < c ; i++ ){
	// 	a[N-i] = cur ;
	// }
	// if( C != 0 ){
	// 	for( int i = 0 ; i < C ; i++ ){
	// 		a[N-i]-- ;
	// 	}
	// }
	// sort(a+1,a+N+1);
	// long long ans = 0 ;
	// for( int i = 1 ; i <= N ; i++ ){
	// 	ans = max((a[i]*f[N-i+1]),ans);
	// }
	// cout << ans << endl ;

	


	return 0 ;
}

Compiler output:
a.cc: In function 'bool check(long long int)':
a.cc:11:25: error: no matching function for call to 'max(int, long long int)'
   11 |                 c += max(0,( a[i] - m/f[N-i+1])) ;
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:11:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   11 |                 c += max(0,( a[i] - m/f[N-i+1])) ;
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:11:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   11 |                 c += max(0,( a[i] - m/f[N-i+1])) ;
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~