QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139758 | #5507. Investors | Flamire | WA | 6ms | 5852kb | C++14 | 1.1kb | 2023-08-14 14:57:22 | 2023-08-14 14:57:24 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int t,n,k,a[6011],sum[6011][6011];pair<ll,int> dp[6011];
int main()
{
scanf("%d",&t);while(t--)
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;++i)scanf("%d",a+i);int cnt=0;
for(int i=0;i<=n+1;++i)for(int j=i;j<=n+1;++j)sum[i][j]=0;
for(int i=1;i<=n;++i)
{
for(int j=i+1;j<=n;++j)if(a[i]>a[j])++sum[i][j],++cnt;
}
if(!k){printf("%d\n",cnt);continue;}
for(int i=n;i;--i)
{
for(int l=1;l+i-1<=n;++l)
{
int r=l+i-1;
sum[l][r]+=sum[l-1][r]+sum[l][r+1]-sum[l-1][r+1];
}
}
int L=0,R=n*n,K=0;ll ans=0;
while(L<=R)
{
int M=L+R>>1;
dp[1]=pair<ll,int>(0,0);
for(int i=2;i<=n;++i)
{
dp[i].first=-1e18;
for(int j=1;j<i;++j)
{
int w=sum[i-1][i]-sum[j-1][i];
dp[i]=max(dp[i],pair<ll,int>(dp[j].first+w-M,dp[j].second+1));
}
}
auto res=dp[1];
for(int i=2;i<=n;++i)res=max(res,dp[i]);
if(res.second>=k)K=M,ans=res.first,L=M+1;else R=M-1;
}
printf("%lld\n",cnt-(ans+1ll*k*K));
}return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
input:
2 6 1 4 5 6 2 2 1 6 2 4 5 6 2 2 1
output:
2 0
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 5852kb
input:
349 6 2 2 1 2 1 2 1 48 12 42 47 39 39 27 25 22 44 45 13 5 48 38 4 37 6 24 10 42 38 12 37 31 19 44 6 29 17 7 12 7 26 35 24 15 9 37 3 27 21 33 29 34 20 14 30 31 21 48 12 1 43 17 46 17 39 40 22 25 2 22 12 4 11 38 12 4 11 1 5 39 44 37 10 19 20 42 45 2 45 37 20 48 34 16 41 23 18 13 44 47 21 29 4 23 18 16...
output:
1 18 15 145 0 2 1 0 13 13 23 0 0 0 1 0 0 0 0 0 0 0 0 161 3 0 0 1 0 4 0 0 0 0 1 2 3 0 0 1 0 0 1 0 0 1 4 0 0 0 0 0 0 0 0 2 0 2 0 2 8 280 0 0 34 4 0 1 0 0 3 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 2 0 0 0 0 0 0 0 8 1 8 0 0 0 0 1 11 5 0 0 0 6 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 6 0 0 0 0 13 1 0 0 0 ...
result:
wrong answer 30th lines differ - expected: '0', found: '4'