QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#260580 | #5435. Clamped Sequence | suibian_xiaozhao# | WA | 12ms | 3932kb | C++23 | 1.4kb | 2023-11-22 13:17:12 | 2023-11-22 13:17:12 |
Judging History
answer
#include "bits/stdc++.h"
#include "bits/extc++.h"
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define hash gp_hash_table
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define lowbit(x) x&(-x)
#define int ll
#define trees tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>
const int mod = 998244353;
void solve() {
int n, d;
cin >> n >> d;
set<int> s;
vector<int> v(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> v[i];
s.insert(v[i]);
}
int k = -1;
// for (auto i: s) {
// int mins = i;
// int maxs = i + d;
// int ans = 0;
// for (int j = 2; j <= n; j++) {
// int a = min(max(mins, v[j]), maxs);
// int b = min(max(mins, v[j - 1]), maxs);
// ans += abs(a - b);
// }
// k = max(ans, k);
// }
for (auto i: s) {
int mins = i - d;
int maxs = i;
int ans = 0;
for (int j = 2; j <= n; j++) {
int a = min(max(mins, v[j]), maxs);
int b = min(max(mins, v[j - 1]), maxs);
ans += abs(a - b);
}
k = max(ans, k);
}
cout << k << endl;
}
signed main() {
IOS
int t = 1;
// cin >> t;
while (t--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 3788kb
input:
2 1 -1000000000 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
2 1000000000 -1000000000 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3660kb
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: 1ms
memory: 3664kb
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: 12ms
memory: 3932kb
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'