QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#372614 | #5435. Clamped Sequence | ucup-team3294# | WA | 0ms | 3628kb | C++23 | 866b | 2024-03-31 16:41:54 | 2024-03-31 16:41:56 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3+5;
int a[N],b[N];
void solve() {
int n,ans=0,d,l,r,res=0,sum=0;
cin>>n>>d;
for(int i=1; i<=n; i++) {
cin>>a[i];
b[i]=a[i];
}
sort(a+1,a+1+n);
for(int ll=1;ll<=n;ll++)
{
for(int rr=ll;rr<=n;rr++)
{
int l=a[ll],r=a[rr];
if(r-l>d) break;
vector<int> c(n+1,0);
for(int i=1;i<=n;i++)
{
if(b[i]<l||b[i]>r)
{
if(b[i]<l) c[i]=l;
else c[i]=r;
}
else c[i]=b[i];
}
int cnt=0;
for(int i=2;i<=n;i++)
{
cnt+=abs(c[i]-c[i-1]);
}
ans=max(ans,cnt);
// if(ans==16)
// {
// cout<<l<<"aa"<<r<<endl;
// }
}
}
cout<<ans<<"\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
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: 3560kb
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: 3628kb
input:
2 1 -1000000000 1000000000
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'