# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163200 | TadijaSebez | 스트랩 (JOI14_straps) | C++11 | 19 ms | 504 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 pb push_back
const int N=2050;
int dp[N];
int main()
{
int n,a,b;
scanf("%i",&n);
for(int i=2;i<=n;i++) dp[i]=-1e9;
vector<int> zero;
int ans=0;
for(int j=1;j<=n;j++)
{
scanf("%i %i",&a,&b);
if(a==0) zero.pb(max(b,0));
else if(a==1) ans+=max(0,b);
else
{
for(int i=n;i>=a;i--) dp[i]=max(dp[i],dp[i-a+1]+b);
for(int i=n-1;i>=1;i--) dp[i]=max(dp[i],dp[i+1]);
}
}
sort(zero.rbegin(),zero.rend());
int tmp=0,sol=0;
for(int i=1;i<=n;i++)
{
if(zero.size()>=i) tmp+=zero[i-1];
sol=max(sol,tmp+dp[i]);
}
printf("%i\n",ans+sol);
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... |