# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
157315 | karma | 스트랩 (JOI14_straps) | C++14 | 27 ms | 16148 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>
#define FileName "test"
#define ll long long
#define pb emplace_back
#define deg first
#define c second
using namespace std;
typedef pair<int, int> pii;
const int N = int(2e3) + 2;
const int oo = int(2e9) + 7;
int f[N][N], Max[N];
int n, a[N], res = 0;
pii val[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(FileName".inp", "r")) {
freopen(FileName".inp", "r", stdin);
freopen(FileName".out", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> val[i].deg >> val[i].c;
fill(f[i], f[i] + n + 1, -oo);
}
sort(val + 1, val + n + 1, [](const pii& x, const pii& y) {
return x.deg > y.deg;
});
/// f(i, j) = max niem vui khi den cai thu i va co j cong ket noi
fill(Max, Max + n + 1, -oo);
f[0][1] = 0; Max[1] = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 0; j <= n; ++j) {
int pre = min(j + 1 - val[i].deg, n);
if(pre < 0) continue;
res = max(res, (f[i][j] = Max[pre] + val[i].c));
}
for(int j = 0; j <= n; ++j) Max[j] = max(Max[j], f[i][j]);
}
cout << res;
}
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... |