Submission #886965

# Submission time Handle Problem Language Result Execution time Memory
886965 2023-12-13T09:32:34 Z efedmrlr Gym Badges (NOI22_gymbadges) C++17
42 / 100
336 ms 32592 KB
#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];
    }
    for(int i = 1; i<=n; i++) {
        for(int j = 0; j<=n; j++) {
            dpnew[j] = INF;
            if(j > 0 && dp[j - 1] <= L[i]) {
                dpnew[j] = min(dpnew[j], dp[j - 1] + X[i]);
            } 

            dpnew[j] = min(dpnew[j], dp[j]);
            
        }
        swap(dp, dpnew);
    }
    // for(int i = 0; i<=n; i++) {
    //     cout<<dp[i]<<" ";
    // }
    // cout<<"\n";
    for(int i = n; i>=0; i--) {
        if(dp[i] < INF) {
            cout<<i<<"\n";
            return;
        }
    }

}

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

Compilation message

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 time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 336 ms 32592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 27 ms 604 KB Output is correct
22 Correct 27 ms 604 KB Output is correct
23 Correct 27 ms 604 KB Output is correct
24 Correct 27 ms 604 KB Output is correct
25 Correct 27 ms 604 KB Output is correct
26 Correct 28 ms 604 KB Output is correct
27 Correct 28 ms 604 KB Output is correct
28 Correct 31 ms 736 KB Output is correct
29 Correct 28 ms 856 KB Output is correct
30 Correct 28 ms 600 KB Output is correct
31 Correct 28 ms 600 KB Output is correct
32 Correct 28 ms 600 KB Output is correct
33 Correct 28 ms 600 KB Output is correct
34 Correct 29 ms 604 KB Output is correct
35 Correct 28 ms 600 KB Output is correct
36 Correct 30 ms 604 KB Output is correct
37 Correct 29 ms 604 KB Output is correct
38 Correct 29 ms 600 KB Output is correct
39 Correct 29 ms 856 KB Output is correct
40 Correct 29 ms 604 KB Output is correct
41 Correct 30 ms 604 KB Output is correct
42 Correct 30 ms 604 KB Output is correct
43 Correct 34 ms 732 KB Output is correct
44 Correct 30 ms 604 KB Output is correct
45 Correct 30 ms 604 KB Output is correct
46 Correct 32 ms 600 KB Output is correct
47 Correct 31 ms 600 KB Output is correct
48 Correct 30 ms 856 KB Output is correct
49 Correct 30 ms 740 KB Output is correct
50 Correct 31 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Runtime error 336 ms 32592 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -