QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279039#5435. Clamped SequenceJalppatel1428RE 0ms0kbC++14718b2023-12-08 03:41:522023-12-08 03:41:53

Judging History

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

  • [2023-12-08 03:41:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-12-08 03:41:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int solve(){
	int n;
	cin>>n;
	int d;
	cin>>d;
	int arr[n];
	int tmp[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
		tmp[i]=arr[i];
	}
	sort(tmp,tmp+n);
	long long int fans=0;
	for(int i=0;i<n;i++){
		int x=tmp[i];
		long long int ans=0;
		int a[n],b[n];
		for(int j=0;j<n;j++){
			a[j]=(arr[j]<x?x:(arr[j]>x+d?x+d:arr[j]));
			b[j]=(arr[j]<x-d?x-d:(arr[j]>x?x:arr[j]));
		}
		for(int j=1;j<n;j++){
			ans+=(abs(a[j]-a[j-1]));
		}
		fans=max(ans,fans);
		ans=0;
		for(int j=1;j<n;j++){
			ans+=(abs(b[j]-b[j-1]));
		}
		fans=max(ans,fans);
	}
	cout<<fans<<endl;	
	
}

int main(){
	int tc;
	cin>>tc;
	while(tc--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

8 3
3 1 4 1 5 9 2 6

output:

6

result: