QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#372487 | #5435. Clamped Sequence | ucup-team3294# | WA | 0ms | 3500kb | C++23 | 1.1kb | 2024-03-31 14:06:19 | 2024-03-31 14:06:25 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3+5;
int a[N],b[N];
void solve()
{
int n,d;
cin>>n>>d;
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i]=a[i];
}
sort(a+1,a+1+n);
int ans=0;
//for(int i=1;i<=n;i++)
//{
for(int j=1;j<=n;j++)
{
int l=a[1],r=a[j];
if(r-l>d) continue;
vector<int> c(n+1,0);
for(int i=1;i<=n;i++)
{
if(b[i]<l||b[i]>r)
{
if(b[i]<l) c[i]=l;
else c[i]=r;
}
else c[i]=b[i];
}
int res=0;
for(int i=2;i<=n;i++)
{
res+=abs(c[i]-c[i-1]);
}
ans=max(ans,res);
}
for(int j=n;j>=1;j--)
{
int l=a[j],r=a[n];
if(r-l>d) continue;
vector<int> c(n+1,0);
for(int i=1;i<=n;i++)
{
if(b[i]<l||b[i]>r)
{
if(b[i]<l) c[i]=l;
else c[i]=r;
}
else c[i]=b[i];
}
int res=0;
for(int i=2;i<=n;i++)
{
res+=abs(c[i]-c[i-1]);
}
ans=max(ans,res);
}
cout<<ans<<endl;
//}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t;
// cin>>t;
while(t--){
solve();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3500kb
input:
8 3 3 1 4 1 5 9 2 6
output:
result:
wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements