# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387519 | CaroLinda | Safety (NOI18_safety) | C++14 | 69 ms | 3744 KiB |
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>
#define ll long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define sz(x) (int)(x.size())
#define mkt make_tuple
#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define debug printf
const int MAXN = 2e5+10 ;
using namespace std ;
int N ;
ll H , ans ;
priority_queue<ll> lef ;
priority_queue< ll , vector<ll>, greater<ll> > rig ;
ll lzLef , lzRig ;
int main()
{
scanf("%d %lld", &N, &H ) ;
for(int i = 1 ; i <= N ; i++ , lzLef -= H , lzRig += H )
{
ll x ;
scanf("%lld", &x ) ;
if(lef.empty())
{
assert(i == 1 ) ;
lef.push(x) ;
rig.push(x);
}
else
{
if( x >= lef.top()+lzLef )
{
rig.push( x-lzRig ) ;
rig.push( x-lzRig ) ;
lef.push( rig.top()+lzRig-lzLef ) ;
rig.pop() ;
ans += abs(x-(lef.top()+lzLef) ) ;
}
else
{
lef.push(x-lzLef) ;
lef.push( x-lzLef ) ;
rig.push( lef.top()+lzLef-lzRig ) ;
lef.pop() ;
ans += abs( x-(rig.top()+lzRig) ) ;
}
}
}
printf("%lld\n" , ans ) ;
}
Compilation message (stderr)
# | 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... |