Submission #1335327

#TimeUsernameProblemLanguageResultExecution timeMemory
1335327minhpnkGym Badges (NOI22_gymbadges)C++20
100 / 100
138 ms24440 KiB
#include <bits/stdc++.h>
#define int long long
#define taskname "main"
#define debug(a, l, r) for (int _i = l; _i <= r; _i++) cout<<(a)[_i]<<' '; cout<<'\n'
#define debug_m(a, li, lj, ri, rj) for (int _i = li; _i <= ri; _i++){for (int _j = lj; _j <= rj; _j++) cout<<(a)[_i][_j]<<' '; cout<<'\n';} cout<<'\n'
using namespace std;
const int maxN = 1e6;
int n,
    w[maxN + 1],
    c[maxN + 1];
struct Box
{
    int l, r;
    inline int w()
    {
        return r - l;
    }
    void print()
    {
        cout << l << ' ' << r << '\n';
    }
    bool operator < (const Box &other) const
    {
        return r - l < other.r - other.l;
    }
} a[maxN + 1];
priority_queue <Box> pq;
void init()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> w[i];
    for (int i = 1; i <= n; i++)
        cin >> c[i];
    for (int i = 1; i <= n; i++)
        a[i] = {c[i], c[i] + w[i]};
    sort(a + 1, a + n + 1, [](Box &x, Box &y){
        return x.r < y.r;
    });
}
void solve()
{
    int tmp_w = 0;
    for (int i = 1; i <= n; i++)
    {
        pq.push(a[i]);
        tmp_w += a[i].w();
        while (tmp_w > a[i].r)
        {
            Box uv_max = pq.top();
            tmp_w -= uv_max.w();
            pq.pop();
        }
    }
    cout << pq.size();
}
signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    if (fopen("main.inp","r"))
    {
        freopen("main.inp","r",stdin);
        freopen("main.out","w",stdout);
    }
    init(); solve();
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen("main.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen("main.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...