QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#266980#5435. Clamped Sequenceucup-team1344RE 0ms0kbC++201.2kb2023-11-26 20:33:102023-11-26 20:33:11

Judging History

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

  • [2023-11-26 20:33:11]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-26 20:33:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i128=__int128_t;
#define inf 0x3f3f3f3f
#define quick std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
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(){ quick
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }

	
	system("pause");
    return 0;
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

8 3
3 1 4 1 5 9 2 6

output:

15

result: