# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387518 | CaroLinda | Safety (NOI18_safety) | C++14 | 95 ms | 5640 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 , a ,b ;
priority_queue<ll> lef ;
priority_queue< ll , vector<ll>, greater<ll> > rig ;
ll lzLef , lzRig ;
void print()
{
debug("y = x*%lld + %lld\n", a , b );
vector<ll> l , r ;
while( !rig.empty() )
{
r.pb( rig.top() ) ;
rig.pop() ;
}
while(!lef.empty())
{
l.pb( lef.top() ) ;
lef.pop() ;
}
for(auto e : r ) rig.push(e) ;
for(auto e : l ) lef.push(e) ;
for(int i = sz(l)-1 ; i >= 0 ; i-- ) debug("%lld ", l[i]+lzLef ) ;
debug("---- ") ;
for(auto e : r ) debug("%lld " , e+lzRig ) ;
debug("\n") ;
}
int main()
{
scanf("%d %lld", &N, &H ) ;
for(int i = 1 ; i <= N ; i++ )
{
ll x ;
scanf("%lld", &x ) ;
a++ ;
b -= 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() ;
}
else
{
lef.push(x-lzLef) ;
lef.push( x-lzLef ) ;
rig.push( lef.top()+lzLef-lzRig ) ;
lef.pop() ;
}
}
//print() ;
//debug("\n") ;
lzLef -= H ;
lzRig += H ;
b -= a*H ;
//print() ;
//debug("\n\n") ;
}
while( !rig.empty() )
{
ll p = rig.top()+lzRig ;
rig.pop() ;
b += p ;
a-- ;
}
printf("%lld\n" , b ) ;
}
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... |