QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#372636 | #5435. Clamped Sequence | ucup-team3294# | TL | 6ms | 3636kb | C++23 | 1.0kb | 2024-03-31 16:58:09 | 2024-03-31 16:58:09 |
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;
if(n==5){
//while(1);
}
for(int i=1; i<=n; i++) {
cin>>a[i];
}
for(int k=-10000;k<=10000;k++){
for(int i=1; i<=n; i++) {
l=a[i]+k;
r=a[i]+d+k;
res=0;
for(int x=1; x<=n; x++) {
if(a[x]>=l&&a[x]<=r) {
b[x]=a[x];
}else if(a[x]<l) b[x]=l;
else if(a[x]>r) b[x]=r;
}
for(int j=2; j<=n; j++) {
res+=abs(b[j]-b[j-1]);
}
ans=max(ans,res);
}
}
for(int k=-10000;k<=10000;k++){
for(int i=1; i<=n; i++) {
l=a[i]-d+k;
r=a[i]+k;
res=0;
for(int x=1; x<=n; x++) {
if(a[x]>=l&&a[x]<=r) {
b[x]=a[x];
}else if(a[x]<l) b[x]=l;
else if(a[x]>r) b[x]=r;
}
for(int j=2; j<=n; j++) {
res+=abs(b[j]-b[j-1]);
}
ans=max(ans,res);
}
}
cout<<ans<<"\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
//cin>>t;
while(t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 3612kb
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: 1ms
memory: 3572kb
input:
2 1 -1000000000 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
2 1000000000 -1000000000 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #4:
score: -100
Time Limit Exceeded
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...