QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372628#5435. Clamped Sequenceucup-team3294#WA 193ms3684kbC++231012b2024-03-31 16:52:592024-03-31 16:53:01

Judging History

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

  • [2024-03-31 16:53:01]
  • 评测
  • 测评结果:WA
  • 用时:193ms
  • 内存:3684kb
  • [2024-03-31 16:52:59]
  • 提交

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,ans=0,d,l,r,res=0,sum=0;
	cin>>n>>d;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}
	for(int k=-100000;k<=100000;k++){
	for(int i=1; i<=n; i++) {
		l=a[i]+k;
		r=a[i]+d+k;
		res=0;
		for(int x=1; x<=n; x++) {
			if(a[x]>=l&&a[x]<=r) {
				b[x]=a[x];
			}else if(a[x]<l) b[x]=l;
			else if(a[x]>r) b[x]=r;
		}
		for(int j=2; j<=n; j++) {
			res+=abs(b[j]-b[j-1]);
		}
		ans=max(ans,res);
	}
	}
	for(int k=-100000;k<=100000;k++){
	for(int i=1; i<=n; i++) {
		l=a[i]-d+k;
		r=a[i]+k;
		res=0;
		for(int x=1; x<=n; x++) {
			if(a[x]>=l&&a[x]<=r) {
				b[x]=a[x];
			}else if(a[x]<l) b[x]=l;
			else if(a[x]>r) b[x]=r;
		}
		for(int j=2; j<=n; j++) {
			res+=abs(b[j]-b[j-1]);
		}
		ans=max(ans,res);
	}
}
	cout<<ans<<"\n";
}
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: 193ms
memory: 3684kb

input:

8 3
3 1 4 1 5 9 2 6

output:

6
10
10
10
10
10
10
10

result:

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