QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#266981 | #5435. Clamped Sequence | ucup-team1344 | RE | 0ms | 0kb | C++20 | 1.1kb | 2023-11-26 20:33:45 | 2023-11-26 20:33:46 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
typedef unsigned long long ull;
#define N 1000010
#define M 998244353
// 998244353 1000000007 1073741824
// 无序map unordered_map
ll n,d;
ll a[N],b[N];
void solve(){
cin>>n>>d;
for(int i=1;i<=n;i++)cin>>a[i];
ll ans=-1;
for(int i=1;i<=n;i++){
ll l=a[i]-d,r=a[i];
ll res=0;
for(int j=1;j<=n;j++){
if(a[j]<l)b[j]=l;
else if(a[j]>r)b[j]=r;
else b[j]=a[j];
}
for(int j=1;j<n;j++){
res+=abs(b[j]-b[j+1]);
}
ans=max(ans,res);
res=0;
l=a[i],r=a[i]+d;
for(int j=1;j<=n;j++){
if(a[j]<l)b[j]=l;
else if(a[j]>r)b[j]=r;
else b[j]=a[j];
}
for(int j=1;j<n;j++){
res+=abs(b[j]-b[j+1]);
}
ans=max(ans,res);
}
cout<<ans<<endl;
}
int main(){
int t=1;
// cin>>t;
while(t--){
solve();
}
system("pause");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
8 3 3 1 4 1 5 9 2 6
output:
15