# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
559493 | Amylopectin | Safety (NOI18_safety) | C++14 | 63 ms | 5452 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 <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
const int mxn = 8e5 + 10;
struct cmple
{
bool operator () (const long long &l,const long long &r)
{
return l < r;
}
};
struct cmpri
{
bool operator () (const long long &l,const long long &r)
{
return l > r;
}
};
priority_queue<long long, vector<long long>, cmple> lef;
priority_queue<long long, vector<long long>, cmpri> rig;
int main()
{
long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
scanf("%lld %lld",&n,&h);
for(i=0; i<n; i++)
{
scanf("%lld",&ch);
if(i == 0)
{
lef.push(ch);
rig.push(ch);
}
else
{
sh = h * i;
lpo = lef.top() - sh;
rpo = rig.top() + sh;
if(ch < lpo)
{
rig.push(lpo - sh);
lef.push(ch + sh);
lef.push(ch + sh);
lef.pop();
ans += lpo - ch;
}
else if(ch > rpo)
{
lef.push(rpo + sh);
rig.push(ch - sh);
rig.push(ch - sh);
rig.pop();
ans += ch - rpo;
}
else
{
lef.push(ch + sh);
rig.push(ch - sh);
}
}
}
printf("%lld\n",ans);
return 0;
}
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... |