#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define endl '\n'
#define f first
#define s second
#define pb(x) push_back(x)
#define int long long
const int MOD = 1e9+7;
const int inf =1e9;
const ll INF = 1e18;
const ll INV2 = 500000004;
class DSU {
vector<int> parent, size;
public:
DSU(int n) {
parent.resize(n+1);
size.resize(n+1);
for (int i=0; i<=n; i++) {
parent[i]=i;
size[i]=1;
}
}
int find (int node) {
if (node==parent[node]) return node;
return parent[node]=find(parent[node]);
}
void unite (int u, int v) {
int pv=find(v);
int pu=find(u);
if (pv==pu) return;
if (size[pu]<size[pv]) swap(pu, pv);
parent[pv]=pu;
size[pu]+=size[pv];
}
int getsize (int node) {
return size[find(node)];
}
};
ll getsqrt(ll x) {
ll val = sqrtl(x) + 2;
while (val * val > x) val--;
return val;
}
bool safe (int i, int j, int n, int m) {
if (i<0 || j<0 || i>=n || j>=m) return false;
return true;
}
ll gcd(ll a, ll b) {
while (b != 0) {
ll temp=b;
b=a%b;
a=temp;
}
return a;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b)*b;
}
vector<int> dx={-1, 0, 1, 0};
vector<int> dy={0, 1, 0, -1};
// SOLUTION STARTS FROM HERE //
bool check (int x, int n, int m, vector<int> &a, vector<int>&b) {
int tn = 0;
int ta = n*m;
for (int i=0; i<n; i++) {
int slots =0;
int best = max(a[i], b[i]);
if (x<=m*best) {
slots = (x+best-1)/best;
} else {
int rem = x-m*best;
slots = m+(rem+b[i]-1)/b[i];
}
tn+=slots;
if (tn>ta) return false;
}
return tn<=ta;
}
void solve() {
int n;
cin>>n;
multiset<int> a;
vector<int> tt(n);
for (int i=0; i<n; i++) {
int x;
cin>>x;
a.insert(x);
tt[i]=x;
}
vector<int> l(n);
for (int i=0; i<n; i++) {
cin>>l[i];
}
int ans = 0;
for (int i=0; i<n; i++) {
auto it = a.find(tt[i]);
if (it != a.end()) {
a.erase(it);
}
int sum=0;
int badge=0;
auto j = a.begin();
while (sum+*j <= l[i] && j!=a.end()) {
sum+=*j;
badge++;
j++;
}
a.insert(tt[i]);
ans=max(ans, badge+1);
}
cout<<ans<<endl;
// m=1, only one weak
/*
for subject i, if he studies ith subject in class x times
and by himself y times then his score will be:
x[i]*a[i] + y[i]+b[i]; we need to maximise the minimum value
of this
*/
}
bool multi=false;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("convention2.in", "r", stdin);
//freopen("convention2.out", "w", stdout);
int t=1;
if (multi) cin>>t;
while (t--) solve();
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... |