Submission #1319929

#TimeUsernameProblemLanguageResultExecution timeMemory
1319929minhpnkGym Badges (NOI22_gymbadges)C++20
0 / 100
1 ms332 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,
    dp[maxN + 1];
struct Gym
{
    int x, l;
    bool operator < (const Gym &other) const
    {
        return l < other.l;
    }
    void print()
    {
        cout << x << ' ' << l << '\n';
    }
} a[maxN + 1];
stack <int> st;
void init()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].x;
    for (int i = 1; i <= n; i++)
        cin >> a[i].l;
    sort(a + 1, a + n + 1);
}
void solve()
{
    int tmp_sum = 0;
    for (int i = 1; i <= n; i++)
    {
        while (!st.empty() && tmp_sum > a[i].l)
        {
            tmp_sum -= st.top();
            st.pop();
        }
        st.push(a[i].x);
        tmp_sum += a[i].x;
    }
    cout << st.size();
}
signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen(taskname".inp","r",stdin);
    freopen(taskname".out","w",stdout);
#endif
    init(); solve();
}

Compilation message (stderr)

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