Submission #8162885


Source Code Expand

Copy
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

vl A(MX), F(MX); 
 
int N; ll K;

bool poss(ll T) {
	ll sum = 0;
	F0R(i, N) {
		if (A[i] * F[i] > T) {
			
			sum += A[i] - T / F[i];
		}
	}

	return sum <= K;
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	cin >> N >> K; A = vl(N); F = vl(N);
	F0R(i, N) cin >> A[i];
	F0R(i, N) cin >> F[i];
	
	sort(all(A)); 
	sort(all(F)); reverse(all(F));
	

	
	ll lo = 0, hi = 1000000000010;
	F0R(i, 50) {
		ll mid = (lo+hi)/2;
		if (poss(mid)) {
			hi = mid;
		} else {
			lo = mid+1;
		}
	}
	if (poss(min(hi, lo))) {
		cout << min(hi, lo) << endl;
	} else {
		cout << max(hi, lo) << endl;
	}
	
	
	
	
	
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Submission Info

Submission Time
Task E - Gluttony
User Geothermal
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1964 Byte
Status
Exec Time 163 ms
Memory 4208 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 500 / 500 sample_01.txt, sample_02.txt, sample_03.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt, sub1_29.txt, sub1_30.txt, sub1_31.txt, sub1_32.txt, sub1_33.txt, sub1_34.txt, sub1_35.txt
Case Name Status Exec Time Memory
sample_01.txt 2 ms 1792 KB
sample_02.txt 2 ms 1792 KB
sample_03.txt 2 ms 1792 KB
sub1_01.txt 122 ms 4208 KB
sub1_02.txt 4 ms 1920 KB
sub1_03.txt 45 ms 2432 KB
sub1_04.txt 12 ms 1920 KB
sub1_05.txt 75 ms 2560 KB
sub1_06.txt 97 ms 2928 KB
sub1_07.txt 3 ms 1792 KB
sub1_08.txt 132 ms 3568 KB
sub1_09.txt 27 ms 2304 KB
sub1_10.txt 35 ms 2560 KB
sub1_11.txt 49 ms 3056 KB
sub1_12.txt 44 ms 2304 KB
sub1_13.txt 21 ms 2048 KB
sub1_14.txt 71 ms 2560 KB
sub1_15.txt 41 ms 2432 KB
sub1_16.txt 87 ms 2800 KB
sub1_17.txt 66 ms 2560 KB
sub1_18.txt 141 ms 4208 KB
sub1_19.txt 111 ms 4208 KB
sub1_20.txt 68 ms 4208 KB
sub1_21.txt 74 ms 4208 KB
sub1_22.txt 121 ms 4208 KB
sub1_23.txt 142 ms 4208 KB
sub1_24.txt 84 ms 4208 KB
sub1_25.txt 137 ms 4208 KB
sub1_26.txt 129 ms 4208 KB
sub1_27.txt 163 ms 4208 KB
sub1_28.txt 150 ms 4208 KB
sub1_29.txt 93 ms 4208 KB
sub1_30.txt 139 ms 4208 KB
sub1_31.txt 101 ms 4208 KB
sub1_32.txt 163 ms 4208 KB
sub1_33.txt 152 ms 4208 KB
sub1_34.txt 4 ms 1792 KB
sub1_35.txt 55 ms 2560 KB