Submission #1183281

#TimeUsernameProblemLanguageResultExecution timeMemory
1183281vukhacminhGym Badges (NOI22_gymbadges)C++20
100 / 100
108 ms12476 KiB
/**
*    Author :  Vu Khac Minh
*    Created : 11.04.2025
**/
#include <bits/stdc++.h>
#define MASK(x) ((1ll) << (x))
#define BIT(x, i) (((x) >> (i)) & (1))
#define c_bit(i) __builtin_popcountll(i) 
#define SET_ON(x, i) ((x) | MASK(i)) 
#define SET_OFF(x, i) ((x) & ~MASK(i)) 
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define db(val) "["#val" = " << (val) << "] "
#define ll long long
using namespace std;
const int maxn = 5e5 + 5;
const int mod = 1e9+7;
void file()
{
    #define Task "ROUNDPRI"
    if(fopen(Task".inp","r"))
    {
        freopen(Task".inp","r",stdin);
        freopen(Task".out","w",stdout);
    }
}
ll n;
pair<ll,ll> a[maxn];
void solve()
{
    cin>>n;
    FOR(i,1,n) cin>>a[i].second;
    FOR(i,1,n) 
    {
        cin>>a[i].first;
        a[i].first+=a[i].second;
    }
    sort(a+1,a+n+1);
    ll cur = 0,res=0;
    priority_queue<ll> pq;
    FOR(i,1,n)
    {
        if(cur + a[i].second <= a[i].first)
        {
            res++;
            cur+=a[i].second;
            pq.push(a[i].second);
        }else
        {
            if(pq.size() && pq.top() > a[i].second)
            {
                cur-=pq.top();
                pq.pop();
                cur+=a[i].second;
                pq.push(a[i].second);
            }
        }
    }
    cout<<res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    file();
    //cin >> ntest;
    while (ntest--)
    {
        solve();
    }

    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void file()':
Main.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(Task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(Task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...