# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46824 | ffresh | 스트랩 (JOI14_straps) | C++17 | 8 ms | 1344 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;
#define ll long long
const int N = 2005;
ll dp[N];
ll pre[N];
int main(){
//freopen("input.txt","r",stdin);
int n;
scanf("%d",&n);
int a,b;
vector<pair<int,int> > bag;
ll cur = 1,cost = 0;
ll pos= 1;
for(int i=1;i<=n+1;++i)dp[i]= -1e18;
for(int i=0;i<n;++i){
scanf("%d%d",&a,&b);
if(b<0){
if(a<=1)continue;
bag.push_back(make_pair(a,b));
}
else{
if(a==0){
pre[pos++]= b;
}
else{
cur += a-1;
cost +=b;
}
}
}
sort(pre+1,pre+pos,greater<ll>());
for(int i=1;i<=n;++i)
pre[i]= pre[i-1] + pre[i];
cur= min(cur,(ll)n);
dp[cur]= cost;
for(int i=0;i<bag.size();++i){
a = bag[i].first, b= bag[i].second;
for(int j=n;j>=cur;--j){
int nb = min(n ,j +a-1);
dp[nb]= max(dp[nb],dp[j]+b);
}
}
ll ret= 0;
for(int i=cur;i<=n;++i){
int sz= i;
ret = max(ret, dp[i] + pre[sz]);
}
cout<<ret<<endl;
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... |