QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#478906#5435. Clamped SequenceUESTC_DECAYALI#WA 0ms3880kbC++17711b2024-07-15 12:43:462024-07-15 12:43:46

Judging History

你现在查看的是最新测评结果

  • [2024-07-15 12:43:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3880kb
  • [2024-07-15 12:43:46]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<algorithm>
#define RI register int
#define CI const int&
using namespace std;
const int N=5005;
int n,d,a[N],rst[N]; long long ans;
inline long long calc(CI l,CI r)
{
	static int b[N]; RI i;
	for (i=1;i<=n;++i)
	if (a[i]<l) b[i]=l; else
	if (a[i]>r) b[i]=r; else b[i]=a[i];
	long long ret=0;
	for (i=1;i<n;++i) ret+=abs(b[i]-b[i+1]);
	return ret;
}
int main()
{
	RI i,j; for (scanf("%d%d",&n,&d),i=1;i<=n;++i)
	scanf("%d",&a[i]),rst[i]=a[i];
	sort(rst+1,rst+n+1); int m=unique(rst+1,rst+n+1)-rst-1;
	for (i=j=1;i<=m;++i)
	{
		while (j<=m&&rst[j]-rst[i]<=d) ++j; --j;
		ans=max(ans,calc(rst[i],rst[j]));
	}
	return printf("%lld",ans),0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3800kb

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: 3880kb

input:

2 1
-1000000000 1000000000

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'