QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#681940#5435. Clamped Sequencelmx111WA 32ms3844kbC++201.6kb2024-10-27 13:05:192024-10-27 13:05:20

Judging History

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

  • [2024-10-27 13:05:20]
  • 评测
  • 测评结果:WA
  • 用时:32ms
  • 内存:3844kb
  • [2024-10-27 13:05:19]
  • 提交

answer

// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db double
const int N = 2e5 + 5;
void solve() {
    ll n, d;
    std::cin >> n >> d;
    std::vector<ll> a(n + 5);
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ll l = a[i], r = a[i] + d;
        ll ans1 = 0;
        for (int j = 1; j < n; j++) {
            ll x, y;
            if (a[j] < l)
                x = l;
            else if (a[j] > r)
                x = r;
            else
                x = a[j];
            if (a[j + 1] < l)
                y = l;
            else if (a[j + 1] > r)
                y = r;
            else
                y = a[j + 1];
            ans1 += std::abs(x - y);
        }
    }
    for (int i = 1; i <= n; i++) {
        ll r = a[i], l = a[i] - d;
        ll ans1 = 0;
        for (int j = 1; j < n; j++) {
            ll x, y;
            if (a[j] < l)
                x = l;
            else if (a[j] > r)
                x = r;
            else
                x = a[j];
            if (a[j + 1] < l)
                y = l;
            else if (a[j + 1] > r)
                y = r;
            else
                y = a[j + 1];
            ans1 += std::abs(x - y);
        }
        ans = std::max(ans, ans1);
    }
    std::cout << ans << '\n';
}
int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0), std::cout.tie(0);
    int t = 1;
    // std::cin >> t;
    while (t--) {
        solve();
    }
    std::cout << std::flush;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3492kb

input:

8 3
3 1 4 1 5 9 2 6

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

2 1
-1000000000 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

2 1000000000
-1000000000 1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #4:

score: 0
Accepted
time: 31ms
memory: 3584kb

input:

5000 10000
-10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10...

output:

49990000

result:

ok 1 number(s): "49990000"

Test #5:

score: 0
Accepted
time: 31ms
memory: 3596kb

input:

5000 10000
10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 1...

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: -100
Wrong Answer
time: 32ms
memory: 3588kb

input:

5000 2897
8987 9710 547 6523 -4484 8892 7360 7473 -5435 8122 -1396 -9963 -1884 -5758 -2930 2867 -260 -3947 -7915 -2428 4137 -1202 -1874 7205 -2852 -6126 -9346 -8662 2294 -4453 -2430 2424 9434 -112 2906 -169 -9489 -1977 68 -9072 2785 -2258 9710 271 8817 6251 3120 4765 -8449 -6625 2617 -3931 -4024 144...

output:

7111077

result:

wrong answer 1st numbers differ - expected: '7111087', found: '7111077'