QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#558453 | #5435. Clamped Sequence | Wuyanru | WA | 0ms | 3816kb | C++14 | 1.6kb | 2024-09-11 16:13:58 | 2024-09-11 16:13:59 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
template<typename A>
using vc=vector<A>;
inline int read()
{
int s=0,w=1;char ch;
while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline ll lread()
{
ll s=0,w=1;char ch;
while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
int pre[5005];
int num[5005];
int a[5005];
int n,k,len;
int main()
{
n=read(),k=read();
for(int i=1;i<=n;i++) num[i]=a[i]=read();
sort(num+1,num+n+1),len=unique(num+1,num+n+1)-num-1;
for(int i=1;i<=n;i++) a[i]=lower_bound(num+1,num+n+1,a[i])-num;
for(int i=2;i<=n;i++) pre[min(a[i-1],a[i])]++,pre[max(a[i-1],a[i])]--;
for(int i=1;i<=len;i++) pre[i]+=pre[i-1];
// for(int i=1;i<=len;i++) printf("%d%c",num[i]," \n"[i==len]);
// for(int i=1;i<=len;i++) printf("%d%c",pre[i]," \n"[i==len]);
ll ans=0;
for(int i=1;i<=len;i++)
{
ll v=0;
for(int j=i+1;j<=len;j++)
{
if(num[j]-num[i]>k) break;
v+=(ll)(num[j]-num[j-1])*pre[j-1];
int rest=k-num[j]+num[i];ans=max(ans,v);
ans=max(ans,v+min(rest,num[i]-num[i-1])*pre[i-1]);
ans=max(ans,v+min(rest,num[j+1]-num[j])*pre[j]);
}
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
input:
8 3 3 1 4 1 5 9 2 6
output:
15
result:
ok 1 number(s): "15"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3764kb
input:
2 1 -1000000000 1000000000
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'