QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768828 | #5435. Clamped Sequence | False0099# | WA | 0ms | 3844kb | C++20 | 1.7kb | 2024-11-21 14:42:43 | 2024-11-21 14:42:43 |
Judging History
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'