/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
const ll INF = 1e13;
ll n;
array<ll, 2> a[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i)cin>> a[i][1];
for(int i = 1; i <= n; ++i)cin>> a[i][0];
sort(a+1, a+1+n, [&](const array<ll, 2> &x, const array<ll, 2>&y){
return (x[0]+x[1] == y[0]+y[1]) ? x[1] < y[1] : x[0] + x[1] < y[0] + y[1];
});
ll sum=0, ans=0;
priority_queue<ll> q;
for(int i = 1; i <= n; ++i){
if(sum <= a[i][0]) ans++;
q.push(a[i][1]); sum += a[i][1];
if(q.size()>ans){
sum -= q.top();
q.pop();
}
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |