QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691945#5435. Clamped Sequencexzin#Compile Error//C++14748b2024-10-31 13:30:312024-10-31 13:30:33

Judging History

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

  • [2024-10-31 13:30:33]
  • 评测
  • [2024-10-31 13:30:31]
  • 提交

answer

#include <bits/stdc++.h>

#define N 5100
#define ll long long
using namespace std;

ll n, d, a[N], b[N], c[N];
ll sum, ans;
ll main() {
    cin>>n>>d;
    for(ll i = 1;i <= n; i++) cin>>a[i], b[i] = a[i];
    sort(b + 1, b + n + 1);
    for(ll i = 1; i <= n; i++) {
        ll low = i, hig = 0, l = 1, r = n;
        sum = 0;
        while (l <= r)  {
            ll mid = (l + r) / 2;
            if(b[mid] - b[low] <= d) hig = mid, l = mid + 1;
            else r = mid - 1;
        }
        for(ll i = 1; i <= n; i++) {
            c[i] = max(a[i], b[low]);
            c[i] = min(c[i], b[hig]);
            sum += abs(c[i] - c[i - 1]);
        }
        ans = max(ans, sum - abs(c[1]));
    }
    cout<<ans<<endl;
}

Details

cc1plus: error: ‘::main’ must return ‘int’