This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using i64=long long;
#define UNUSED -1
#define all(x) x.begin(),x.end()
#define pb push_back
const int mod=1e9+7,inf=1e9+1;
const int N=2e5;
int n,h;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>h;
vector<int>b;
i64 rez=0;
int last_l=0,last_r=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
b.insert(lower_bound(all(b) , x),x);
b.insert(lower_bound(all(b) , x),x);
for(int j=0;j<i;j++)
{
b[j]-=h;
}
for(int j=i;j<2*i;j++)
{
b[j]+=h;
}
//rez se schimba, intervale disjuncte
if(i!=1)
{
rez+=max(last_l-x , 0);
rez+=max(x-last_r , 0);
}
last_l=b[i-1],last_r=b[i];
}
cout<<rez;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |