QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#691986 | #5435. Clamped Sequence | xzin# | WA | 0ms | 3644kb | C++14 | 749b | 2024-10-31 13:34:32 | 2024-10-31 13:34:32 |
Judging History
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;
int 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 = i, l = i, 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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
input:
8 3 3 1 4 1 5 9 2 6
output:
15
result:
ok 1 number(s): "15"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
2 1 -1000000000 1000000000
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'