QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#768831 | #5435. Clamped Sequence | False0099# | WA | 0ms | 3596kb | C++20 | 1.7kb | 2024-11-21 14:43:41 | 2024-11-21 14:43:42 |
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 _ = 1; _ <= n; _++)
{
int maxx = a[_];
int minn = max(0ll, a[_] - 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[_];
maxx = a[_] + 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();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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: 3544kb
input:
2 1 -1000000000 1000000000
output:
1000000000
result:
wrong answer 1st numbers differ - expected: '1', found: '1000000000'