Submission #992228

# Submission time Handle Problem Language Result Execution time Memory
992228 2024-06-04T06:57:43 Z inventiontime Gym Badges (NOI22_gymbadges) C++17
0 / 100
141 ms 17052 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int ll
#define endl '\n' //comment for interactive
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
#define pb push_back
#define re resize
#define ff first
#define ss second
 
#define all(x) (x).begin(), (x).end()
#define all1(x) (x).begin()+1, (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
 
#define print(x) cout << #x << ": " << x << endl << flush
 
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef vector<vi> vvi;
typedef priority_queue<int> pq;
 
template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }
 
const int inf = 1e17;
 
void solve() {
 
    int n; cin >> n;
    vti g(n+1);
    loop1(i, n) cin >> g[i][1]; // x
    loop1(i, n) cin >> g[i][2]; // l
    loop1(i, n) g[i][0] = g[i][1] + g[i][2];
    sort(all1(g));
 
    set<int> st;
    int exp = 0;
    loop1(i, n) {
        if(exp <= g[i][2]) {
            st.insert(g[i][1]);
            exp += g[i][1];
        } else if(exp - *(--st.end()) <= g[i][2]) {
            auto it = --st.end();
            exp -= *it;
            st.erase(it);
            st.insert(g[i][1]);
            exp += g[i][1];
        }
    }

    cout << st.size() << endl;
 
}
 
signed main() {
 
    fast_io;
 
    int t = 1; //cin >> t;
    while(t--)
        solve();
 
    return 0;
 
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 17052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -