Submission #886966

#TimeUsernameProblemLanguageResultExecution timeMemory
886966efedmrlrGym Badges (NOI22_gymbadges)C++17
100 / 100
345 ms29892 KiB
#include <bits/stdc++.h>

#define int long long int
#define MP make_pair
#define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)
#define pb push_back

const int N = 5e3+5;
const int MOD = 1e9+7;
const int INF = 1e17;
using namespace std;

void fastio() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
}
int n,m,q;
vector<int> dp(N, INF), dpnew(N, INF);
vector<int> L, X;
vector<array<int,2> > srt;
bool comp(array<int,2> &x, array<int,2> &y) {
    return x[0] + x[1] < y[0] + y[1];
}
void solve() {
    cin>>n;
    srt.resize(n);
    L.assign(n+1, 0);
    X.assign(n+1, 0);
    REP(i,n) cin>>srt[i][0];
    REP(i,n) cin>>srt[i][1];
    dp[0] = 0;
    sort(srt.begin(), srt.end(), comp);
    REP(i,n) {
        X[i + 1] = srt[i][0];
        L[i + 1] = srt[i][1];
    }

    priority_queue<int> pq;
    int last = 0;
    for(int i = 1; i<=n; i++) {
        pq.push(X[i]);
        if(last > L[i]) {
            last -= pq.top();
            pq.pop(); // pop worst
        }   
        last += X[i];

    }
    cout<<pq.size()<<"\n";
}

signed main() {
    // fastio();
    solve();
}   

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:5:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)
      |                          ^
Main.cpp:29:5: note: in expansion of macro 'REP'
   29 |     REP(i,n) cin>>srt[i][0];
      |     ^~~
Main.cpp:5:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)
      |                          ^
Main.cpp:30:5: note: in expansion of macro 'REP'
   30 |     REP(i,n) cin>>srt[i][1];
      |     ^~~
Main.cpp:5:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)
      |                          ^
Main.cpp:33:5: note: in expansion of macro 'REP'
   33 |     REP(i,n) {
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...