# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
157200 | EntityIT | 스트랩 (JOI14_straps) | C++14 | 56 ms | 31952 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |