QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#478906 | #5435. Clamped Sequence | UESTC_DECAYALI# | WA | 0ms | 3880kb | C++17 | 711b | 2024-07-15 12:43:46 | 2024-07-15 12:43:46 |
Judging History
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;
}
詳細信息
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'