QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401780 | #5435. Clamped Sequence | xjt05 | RE | 0ms | 0kb | C++23 | 725b | 2024-04-29 12:52:16 | 2024-04-29 12:52:17 |
answer
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<vector>
#include<map>
#include<set>
#pragma GCC optimize(3,"Ofast","inline")
#define endl "\n"
using namespace std;
typedef long long ll;
ll n,m,a[5200],u=0;
ll check(ll x)
{
ll ans=0,d=0,f=0,os=0;
ll o=x+m;
for(ll i=2;i<=n;i++)
{
ll z;
if(a[i]<=x)
z=x;
else if(a[i]>=o)
z=o;
else z=a[i];
ll r;
if(a[i-1]<=x)
r=x;
else if(a[i-1]>=o)
r=o;
else r=a[i-1];
os+=abs(r-z);
}
u=max(u,os);
}
int main()
{
set<ll>q;
cin>>n>>m;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
q.insert(a[i]);
}
for(auto t:q)
{
check(t);
}
cout<<u<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
8 3 3 1 4 1 5 9 2 6