Submission #157200

#TimeUsernameProblemLanguageResultExecution timeMemory
157200EntityIT스트랩 (JOI14_straps)C++14
100 / 100
56 ms31952 KiB
#include<bits/stdc++.h>

using namespace std;

using LL = long long;
const LL infLL = (LL)1e18 + 123;
const int N = (int)2e3 + 5;

int n;
LL f[N][N];

struct Str {
    int a, b;
    Str(int _a = 0, int _b = 0) : a(_a), b(_b) {}
    bool operator<(const Str &_) const { return a > _.a; }
} str[N];

int main() {
    scanf(" %d", &n);
    for (int i = 1; i <= n; ++i) scanf(" %d %d", &str[i].a, &str[i].b);

    sort(str + 1, str + n + 1);
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) f[i][j] = -infLL;
    }

    f[0][1] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= n; ++j) if (f[i][j] > -infLL) {
            f[i + 1][j] = max(f[i + 1][j], f[i][j]);
            if (j) {
                int nJ = j - 1 + str[i + 1].a;
                if (nJ > n) nJ = n;
                f[i + 1][nJ] = max(f[i + 1][nJ], f[i][j] + str[i + 1].b);
            }
        }
    }

    LL ans = -infLL;
    for (int j = 0; j <= n; ++j) ans = max(ans, f[n][j]);

    cout << ans << '\n';

    return 0;
}

Compilation message (stderr)

straps.cpp: In function 'int main()':
straps.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %d", &n);
     ~~~~~^~~~~~~~~~~
straps.cpp:20:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; ++i) scanf(" %d %d", &str[i].a, &str[i].b);
                                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...