이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[2005];
const ll inf = 1e18;
int main () {
int n;
cin >> n;
vector<ll> cand {};
for (int i = 2; i <= 2000; i++) dp[i] = -inf;
ll base = 0;
while (n--) {
ll a, b;
cin >> a >> b;
if (a && b >= 0) {
for (int i = 2000; i >= a; i--) dp[i] = dp[i-a+1];
for (int i = 1; i < a; i++) dp[i] = 0;
base += b;
} else if (b >= 0) cand.push_back(b);
else if (a > 1) for (int i = 2000; i >= a; i--) dp[i] = max(dp[i], dp[i-a+1] + b);
}
sort(cand.rbegin(), cand.rend());
int sz = cand.size();
for (int i = 1; i < sz; i++) cand[i] += cand[i-1];
ll ans = 0;
if (!cand.empty()) for (int i = 0; i < 2000; i++) ans = max(ans, dp[i+1] + cand[min(i, sz-1)]);
cout << ans+base << '\n';
return 0;
}
# | 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... |