QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#357510 | #3056. Live Programming | Kevin5307 | WA | 2ms | 6492kb | C++20 | 1.3kb | 2024-03-18 22:09:12 | 2024-03-18 22:09:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int n,t;
ll f[4004],p[4004],l[4004];
ll dp[4004][4004];
deque<pair<ll,ll>> dq[4004];
long double slope(pair<ll,ll> a,pair<ll,ll> b)
{
return 1.0L*(b.first-a.first)/(b.second-a.second);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>t;
for(int i=1;i<=n;i++)
cin>>l[i]>>p[i]>>f[i];
for(int i=1;i<=n;i++)
for(int j=1;j<n;j++)
if(f[j]>f[j+1])
{
swap(f[j],f[j+1]);
swap(p[j],p[j+1]);
swap(l[j],l[j+1]);
}
for(int i=0;i<=n;i++)
for(int j=0;j<=t;j++)
dp[i][j]=-1e14;
dp[0][0]=0;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=t;j++) if(dp[i-1][j]>=-1e13)
{
ll vy=dp[i-1][j]-f[i-1]*f[i-1];
ll vx=f[i-1]+f[i-1];
while(dq[j].size()>1&&slope(dq[j][dq[j].size()-2],dq[j].back())<slope(dq[j].back(),pair<ll,ll>(vy,vx)))
dq[j].pop_back();
dq[j].emplace_back(vy,vx);
}
for(int j=0;j<=t-l[i];j++) if(dq[j].size())
{
while(dq[j].size()>1&&slope(dq[j][0],dq[j][1])<-f[i])
dq[j].pop_front();
dp[i][j+l[i]]=dq[j][0].first+dq[j][0].second*f[i]-f[i]*f[i]+p[i];
}
dp[i][l[i]]=max(dp[i][l[i]],p[i]);
}
ll ans=0;
for(int i=0;i<=n;i++)
for(int j=0;j<=t;j++)
ans=max(ans,dp[i][j]);
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6492kb
input:
2 10 10 200 1 10 100 100
output:
200
result:
ok single line: '200'
Test #2:
score: 0
Accepted
time: 2ms
memory: 6304kb
input:
3 15 5 100 1 5 100 2 5 100 4
output:
295
result:
ok single line: '295'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 6472kb
input:
3 10 5 200 200 5 200 201 5 300 1
output:
300
result:
wrong answer 1st lines differ - expected: '399', found: '300'