Submission #1279170

#TimeUsernameProblemLanguageResultExecution timeMemory
1279170ducdevGym Badges (NOI22_gymbadges)C++17
0 / 100
962 ms204432 KiB
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAX_N = 1e6;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n, sz;
pair<int, int> a[MAX_N + 5];

namespace SUBTASK_3 {
    const int N = 5000;

    ll dp[N + 5][N + 5];

    void Solve() {
        sort(a + 1, a + n + 1);

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                dp[i][j] = 1e18;
            };
        };

        dp[0][0] = 0;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= i; j++) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
                if (dp[i][j] <= a[i + 1].first) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + a[i + 1].second);
            };
        };

        for (int i = n; i >= 0; i--) {
            if (dp[n][i] != 1e18) {
                cout << i << '\n';
                break;
            };
        };
    };
};  // namespace SUBTASK_3

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen("MAIN.INP", "r")) {
        freopen("MAIN.INP", "r", stdin);
        freopen("MAIN.OUT", "w", stdout);
    };

    cin >> n;

    for (int i = 1; i <= n; i++) cin >> a[i].second;
    for (int i = 1; i <= n; i++) cin >> a[i].first;

    SUBTASK_3::Solve();
};

Compilation message (stderr)

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