QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372487#5435. Clamped Sequenceucup-team3294#WA 0ms3500kbC++231.1kb2024-03-31 14:06:192024-03-31 14:06:25

Judging History

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

  • [2024-03-31 14:06:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3500kb
  • [2024-03-31 14:06:19]
  • 提交

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();
	}
}

Details

Tip: Click on the bar to expand more detailed information

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