QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#279041 | #5435. Clamped Sequence | Jalppatel1428 | WA | 0ms | 3708kb | C++14 | 719b | 2023-12-08 03:43:00 | 2023-12-08 03:43:01 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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'