# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
157200 | EntityIT | 스트랩 (JOI14_straps) | C++14 | 56 ms | 31952 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |