QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#279041#5435. Clamped SequenceJalppatel1428WA 0ms3708kbC++14719b2023-12-08 03:43:002023-12-08 03:43:01

Judging History

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

  • [2023-12-08 03:43:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3708kb
  • [2023-12-08 03:43:00]
  • 提交

answer

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

void 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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3708kb

input:

8 3
3 1 4 1 5 9 2 6

output:

6
13
18
18
18
18
18
18

result:

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