QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768828#5435. Clamped SequenceFalse0099#WA 0ms3844kbC++201.7kb2024-11-21 14:42:432024-11-21 14:42:43

Judging History

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

  • [2024-11-21 14:42:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-11-21 14:42:43]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
int INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
typedef pair<int, int> PII;
void init()
{
}
void solve()
{
    int n, d;
    cin >> n >> d;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        int maxx = a[i];
        int minn = max(0ll, a[i] - d);
        vector<int> b = a;
        int sum = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] < minn)
            {
                b[i] = minn;
            }
            if (a[i] >= minn && a[i] <= maxx)
            {
                b[i] = a[i];
            }
            if (a[i] > maxx)
            {
                b[i] = maxx;
            }
            if (i >= 2)
            {
                sum += abs(b[i] - b[i - 1]);
            }
        }
        res = max(res, sum);
        minn = a[i];
        maxx = a[i] + d;
        b = a;
        sum = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] < minn)
            {
                b[i] = minn;
            }
            if (a[i] >= minn && a[i] <= maxx)
            {
                b[i] = a[i];
            }
            if (a[i] > maxx)
            {
                b[i] = maxx;
            }
            if (i >= 2)
            {
                sum += abs(b[i] - b[i - 1]);
            }
        }
        res = max(res, sum);
    }
    cout << res << endl;
}
signed main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    int t;
    t = 1;
    //    cin>>t;
    init();
    while (t--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3560kb

input:

2 1
-1000000000 1000000000

output:

1000000000

result:

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