QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673848#5435. Clamped SequencexcyyyyyWA 0ms3860kbC++20796b2024-10-25 11:01:422024-10-25 11:01:42

Judging History

This is the latest submission verdict.

  • [2024-10-25 11:01:42]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3860kb
  • [2024-10-25 11:01:42]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define N 5005
#define fr first
#define se second
#define ls u<<1
#define rs u<<1|1
#define M 10000005
#define p 998244353
#define pb push_back
#define ll long long
#define inf 0x3f3f3f3f
#define pii pair<int,int>
int n,a[N],d;
ll calc(int l,int r){
    ll ans=0;
    for(int i=1;i<n;i++){
        int L=min(a[i],a[i+1]),R=max(a[i],a[i+1]);
        if(max(l,L)<=min(r,R))
            ans+=min(r,R)-max(l,L);
    }
    return ans;
}
int main(){
    freopen("ans.in","r",stdin);
    scanf("%d%d",&n,&d);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    ll ans=0;
    for(int i=1,l,r;i<n;i++){
        l=min(a[i],a[i+1]),r=max(a[i],a[i+1]);
        ans=max({ans,calc(l,l+d),calc(r-d,r)});
    }
    printf("%lld\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8 3
3 1 4 1 5 9 2 6

output:

0

result:

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