# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46819 | ffresh | 스트랩 (JOI14_straps) | C++17 | 8 ms | 1984 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;
int dp[N];
int pre[N];
int main(){
//freopen("input.txt","r",stdin);
int n;
scanf("%d",&n);
int a,b;
vector<pair<int,int> > bag;
int cur = 1,cost = 0;
int pos= 1;
for(int i=1;i<=n+1;++i)dp[i]= -2e9-150;
dp[1]= 0;
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<int>());
for(int i=1;i<=n;++i)
pre[i]= pre[i-1] + pre[i];
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);
}
}
int 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... |