Submission #8169063


Source Code Expand

Copy
/*input
3 8
4 2 1
2 3 1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=400005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){

    if(b<=0) return 1;
    if(a<=0) return 0;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
ll arr[maxn],f[maxn];
int n;
ll k;
bool wk(ll mid){
    ll z=k;
    REP(i,n){
        if(arr[i]*f[n-i-1]>mid){
            z-=(arr[i]-mid/(f[n-i-1]));
        }
    }
    if(z>=0) return true;
    return false;
}
int main(){
    cin>>n>>k;
    REP(i,n) cin>>arr[i];
    REP(i,n) cin>>f[i];
    sort(arr,arr+n);
    sort(f,f+n);
    ll l=0,r=1e12+1;
    while(l<r){
        ll mid=(l+r)/2;
        if(wk(mid)) r=mid;
        else l=mid+1;
    }
    cout<<r;
}

Submission Info

Submission Time
Task E - Gluttony
User zaneyu
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1700 Byte
Status AC
Exec Time 221 ms
Memory 5888 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 38
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 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 AC 2 ms 2304 KB
sample_02.txt AC 2 ms 2304 KB
sample_03.txt AC 2 ms 2304 KB
sub1_01.txt AC 215 ms 5888 KB
sub1_02.txt AC 6 ms 2304 KB
sub1_03.txt AC 77 ms 2816 KB
sub1_04.txt AC 19 ms 2432 KB
sub1_05.txt AC 102 ms 3072 KB
sub1_06.txt AC 131 ms 3200 KB
sub1_07.txt AC 4 ms 2304 KB
sub1_08.txt AC 179 ms 5632 KB
sub1_09.txt AC 51 ms 2688 KB
sub1_10.txt AC 76 ms 3072 KB
sub1_11.txt AC 102 ms 5376 KB
sub1_12.txt AC 60 ms 2688 KB
sub1_13.txt AC 29 ms 2432 KB
sub1_14.txt AC 96 ms 2944 KB
sub1_15.txt AC 67 ms 2816 KB
sub1_16.txt AC 122 ms 3200 KB
sub1_17.txt AC 95 ms 2944 KB
sub1_18.txt AC 200 ms 5888 KB
sub1_19.txt AC 180 ms 5888 KB
sub1_20.txt AC 150 ms 5888 KB
sub1_21.txt AC 154 ms 5888 KB
sub1_22.txt AC 193 ms 5888 KB
sub1_23.txt AC 202 ms 5888 KB
sub1_24.txt AC 161 ms 5888 KB
sub1_25.txt AC 197 ms 5888 KB
sub1_26.txt AC 198 ms 5888 KB
sub1_27.txt AC 221 ms 5888 KB
sub1_28.txt AC 212 ms 5888 KB
sub1_29.txt AC 173 ms 5888 KB
sub1_30.txt AC 205 ms 5888 KB
sub1_31.txt AC 178 ms 5888 KB
sub1_32.txt AC 221 ms 5888 KB
sub1_33.txt AC 214 ms 5888 KB
sub1_34.txt AC 4 ms 2304 KB
sub1_35.txt AC 90 ms 3072 KB